Skip to content

Commit 419a508

Browse files
massimilianobragliaruflin
authored andcommitted
Base PHP-cs-fixer migration to version 2 plus style fix (#1555)
* Introduce php-cs-fixer 2 * Fix styles * Add linting job / check to CI
1 parent c15fff3 commit 419a508

File tree

426 files changed

+1061
-559
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

426 files changed

+1061
-559
lines changed

.php_cs

+19-25
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,26 @@
11
<?php
22

3-
$finder = Symfony\CS\Finder\DefaultFinder::create()
4-
->in(['lib', 'test']);
3+
$finder = PhpCsFixer\Finder::create()
4+
->exclude(['vendor', 'var'])
5+
->in([__DIR__])
6+
;
57

6-
$config = Symfony\CS\Config\Config::create()
7-
->setUsingCache(true)
8-
->level(Symfony\CS\FixerInterface::SYMFONY_LEVEL)
9-
->fixers([
10-
// [contrib] Multi-line whitespace before closing semicolon are prohibited.
11-
'multiline_spaces_before_semicolon',
12-
// [contrib] There should be no blank lines before a namespace declaration.
13-
'no_blank_lines_before_namespace',
14-
// [contrib] Ordering use statements.
15-
'ordered_use',
16-
// [contrib] Annotations should be ordered so that param annotations come first, then throws annotations, then return annotations.
17-
'phpdoc_order',
18-
// [contrib] Arrays should use the short syntax.
19-
'short_array_syntax',
20-
// [contrib] Ensure there is no code on the same line as the PHP open tag.
21-
'newline_after_open_tag',
22-
// [contrib] Use null coalescing operator ?? where possible
23-
'ternary_to_null_coalescing',
24-
// [contrib] There should not be useless else cases.
25-
'no_useless_else',
26-
// [contrib] Use dedicated PHPUnit assertions for better error messages.
8+
$config = PhpCsFixer\Config::create()
9+
->setFinder($finder)
10+
->setRules([
11+
'@PSR2' => true,
12+
'@Symfony' => true,
13+
'psr0' => false,
14+
'single_blank_line_before_namespace' => false,
15+
'ordered_imports' => true,
16+
'array_syntax' => ['syntax' => 'short'],
17+
'phpdoc_order' => true,
18+
'blank_line_after_namespace' => true,
19+
'ternary_to_null_coalescing' => true,
20+
'no_useless_else' => true,
2721
'@PHPUnit60Migration:risky' => true,
28-
//'php_unit_dedicate_assert' => ['target' => 'newest'],
22+
'php_unit_dedicate_assert' => ['target' => 'newest'],
2923
])
30-
->finder($finder);
24+
;
3125

3226
return $config;

.travis.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ env:
2020
- TARGET="71"
2121
- TARGET="72"
2222
- TARGET="73"
23+
- TARGET="Lint"
2324

2425
before_install:
2526
# check running "docker engine" and "docker-compose" version on travis
@@ -41,7 +42,8 @@ before_script:
4142
- sudo sysctl -w vm.max_map_count=262144
4243

4344
script:
44-
- make tests TARGET=$TARGET
45+
- if [ "$TARGET" != "Lint" ] ; then make tests TARGET=$TARGET ; fi
46+
- if [ "$TARGET" == "Lint" ] ; then make check-style ; fi
4547

4648
after_script:
4749
- cat /var/log/elasticsearch/*.log

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ All notable changes to this project will be documented in this file based on the
1212
* Added `BucketSelector` aggregation [#1554](https://github.com/ruflin/Elastica/pull/1554)
1313
* Added `DerivativeAggregation` [#1553](https://github.com/ruflin/Elastica/pull/1553)
1414
* The preferred type name is [_doc](https://www.elastic.co/guide/en/elasticsearch/reference/6.5/removal-of-types.html), so that index APIs have the same path as they will have in 7.0
15+
* Introduced new version of PHP-CS-Fixer and new Lint travis step. [#1555](https://github.com/ruflin/Elastica/pull/1555)
1516

1617
### Improvements
1718

Makefile

+11-2
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ tests:
6161
make start
6262
mkdir -p build
6363

64-
docker run -e "ES_HOST=elasticsearch" --network=elastica_esnet elastica_elastica make phpunit
64+
docker run -e "ES_HOST=elasticsearch" --network=elastica_esnet elastica_elastica make phpunit
6565
docker cp elastica:/elastica/build/coverage/ $(shell pwd)/build/coverage
6666

6767
# Makes it easy to run a single test file. Example to run IndexTest.php: make test TEST="IndexTest.php"
@@ -79,7 +79,16 @@ doc:
7979
# Uses the preconfigured standards in .php_cs
8080
.PHONY: lint
8181
lint:
82-
${RUN_ENV} php-cs-fixer fix
82+
${RUN_ENV} php-cs-fixer fix --allow-risky=yes
83+
84+
.PHONY: check-style
85+
check-style:
86+
docker build -t ruflin/elastica-dev-base -f env/elastica/${TARGET} env/elastica/
87+
docker build -t ruflin/elastica .
88+
make start
89+
mkdir -p build
90+
91+
${RUN_ENV} php-cs-fixer fix --allow-risky=yes --dry-run
8392

8493
.PHONY: loc
8594
loc:

env/elastica/Lint

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# This image is the base image for the Elastica development and includes all parts which rarely change
2+
# PHP 7 Docker file with Composer installed
3+
FROM php:7.2
4+
MAINTAINER Nicolas Ruflin <[email protected]>
5+
6+
RUN apt-get update && apt-get install -y \
7+
cloc \
8+
git \
9+
graphviz \
10+
libxslt-dev \
11+
nano \
12+
zip unzip \
13+
wget
14+
# XSL and Graphviz for PhpDocumentor
15+
16+
RUN docker-php-ext-install sockets xsl
17+
18+
RUN rm -r /var/lib/apt/lists/*
19+
20+
# Xdebug for coverage report
21+
RUN pecl install xdebug-2.6.1
22+
23+
RUN echo "memory_limit=1024M" >> /usr/local/etc/php/conf.d/memory-limit.ini
24+
RUN echo "date.timezone=UTC" >> /usr/local/etc/php/conf.d/timezone.ini
25+
26+
# Install and setup composer
27+
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
28+
ENV COMPOSER_HOME /root/composer
29+
30+
# Add composer bin to the environment
31+
ENV PATH=/root/composer/vendor/bin:$PATH
32+
33+
COPY composer.json /root/composer/
34+
35+
RUN composer global remove --no-update phpdocumentor/phpdocumentor -vvv
36+
RUN composer global require --no-update friendsofphp/php-cs-fixer:^2.0
37+
38+
# Install development tools, prefer source removed as automatic fallback now
39+
RUN composer global install -vvv

env/elastica/composer.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
"require": {
1515
"php": "^7.0",
1616
"phpdocumentor/phpdocumentor": "^2.9",
17-
"fabpot/php-cs-fixer": "1.11.*",
1817
"mayflower/php-codebrowser": "~1.1",
1918
"pdepend/pdepend": "^2.5",
2019
"phploc/phploc": "^4.0",
@@ -23,4 +22,4 @@
2322
"sebastian/phpcpd": "~3.0",
2423
"squizlabs/php_codesniffer": "~3.3"
2524
}
26-
}
25+
}

lib/Elastica/AbstractUpdateAction.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
namespace Elastica;
34

45
/**
@@ -108,7 +109,7 @@ public function getIndex()
108109
*
109110
* @return $this
110111
*
111-
* @link https://www.elastic.co/blog/versioning
112+
* @see https://www.elastic.co/blog/versioning
112113
*/
113114
public function setVersion($version)
114115
{
@@ -171,7 +172,7 @@ public function hasVersionType()
171172
*
172173
* @return $this
173174
*
174-
* @link https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-parent-field.html
175+
* @see https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-parent-field.html
175176
*/
176177
public function setParent($parent)
177178
{

lib/Elastica/Aggregation/AbstractAggregation.php

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
namespace Elastica\Aggregation;
34

45
use Elastica\Exception\InvalidException;

lib/Elastica/Aggregation/AbstractSimpleAggregation.php

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
namespace Elastica\Aggregation;
34

45
use Elastica\Exception\InvalidException;

lib/Elastica/Aggregation/AbstractTermsAggregation.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
namespace Elastica\Aggregation;
34

45
/**
@@ -61,7 +62,7 @@ public function setExclude($pattern, $flags = null)
6162
/**
6263
* Sets the amount of terms to be returned.
6364
*
64-
* @param int $size The amount of terms to be returned.
65+
* @param int $size the amount of terms to be returned
6566
*
6667
* @return $this
6768
*/
@@ -73,7 +74,7 @@ public function setSize($size)
7374
/**
7475
* Sets how many terms the coordinating node will request from each shard.
7576
*
76-
* @param int $shard_size The amount of terms to be returned.
77+
* @param int $shard_size the amount of terms to be returned
7778
*
7879
* @return $this
7980
*/

lib/Elastica/Aggregation/Avg.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
<?php
2+
23
namespace Elastica\Aggregation;
34

45
/**
56
* Class Avg.
67
*
7-
* @link https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-avg-aggregation.html
8+
* @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-avg-aggregation.html
89
*/
910
class Avg extends AbstractSimpleAggregation
1011
{

lib/Elastica/Aggregation/AvgBucket.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
<?php
2+
23
namespace Elastica\Aggregation;
34

45
use Elastica\Exception\InvalidException;
56

67
/**
78
* Class AvgBucket.
89
*
9-
* @link https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-avg-bucket-aggregation.html
10+
* @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-avg-bucket-aggregation.html
1011
*/
1112
class AvgBucket extends AbstractAggregation
1213
{
@@ -18,7 +19,7 @@ public function __construct($name, $bucketsPath = null)
1819
{
1920
parent::__construct($name);
2021

21-
if ($bucketsPath !== null) {
22+
if (null !== $bucketsPath) {
2223
$this->setBucketsPath($bucketsPath);
2324
}
2425
}

lib/Elastica/Aggregation/BucketScript.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
<?php
2+
23
namespace Elastica\Aggregation;
34

45
use Elastica\Exception\InvalidException;
56

67
/**
78
* Class BucketScript.
89
*
9-
* @link https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-bucket-script-aggregation.html
10+
* @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-bucket-script-aggregation.html
1011
*/
1112
class BucketScript extends AbstractAggregation
1213
{
@@ -19,11 +20,11 @@ public function __construct($name, $bucketsPath = null, $script = null)
1920
{
2021
parent::__construct($name);
2122

22-
if ($bucketsPath !== null) {
23+
if (null !== $bucketsPath) {
2324
$this->setBucketsPath($bucketsPath);
2425
}
2526

26-
if ($script !== null) {
27+
if (null !== $script) {
2728
$this->setScript($script);
2829
}
2930
}

lib/Elastica/Aggregation/BucketSelector.php

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
<?php
2+
23
namespace Elastica\Aggregation;
34

45
/**
56
* Class BucketSelector.
6-
* @link https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-bucket-selector-aggregation.html
7+
*
8+
* @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-bucket-selector-aggregation.html
79
*/
810
class BucketSelector extends AbstractSimpleAggregation
911
{
@@ -16,11 +18,11 @@ public function __construct(string $name, array $bucketsPath = null, string $scr
1618
{
1719
parent::__construct($name);
1820

19-
if ($bucketsPath !== null) {
21+
if (null !== $bucketsPath) {
2022
$this->setBucketsPath($bucketsPath);
2123
}
2224

23-
if ($script !== null) {
25+
if (null !== $script) {
2426
$this->setScript($script);
2527
}
2628
}
@@ -49,4 +51,3 @@ public function setGapPolicy(string $gapPolicy = 'skip')
4951
return $this->setParam('gap_policy', $gapPolicy);
5052
}
5153
}
52-

lib/Elastica/Aggregation/Cardinality.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
<?php
2+
23
namespace Elastica\Aggregation;
34

45
/**
56
* Class Cardinality.
67
*
7-
* @link https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-cardinality-aggregation.html
8+
* @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-cardinality-aggregation.html
89
*/
910
class Cardinality extends AbstractSimpleAggregation
1011
{

lib/Elastica/Aggregation/Children.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
<?php
2+
23
namespace Elastica\Aggregation;
34

45
/**
56
* Class Children.
67
*
7-
* @link https://www.elastic.co/guide/en/elasticsearch/reference/1.7/search-aggregations-bucket-children-aggregation.html
8+
* @see https://www.elastic.co/guide/en/elasticsearch/reference/1.7/search-aggregations-bucket-children-aggregation.html
89
*/
910
class Children extends AbstractAggregation
1011
{

lib/Elastica/Aggregation/DateHistogram.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
<?php
2+
23
namespace Elastica\Aggregation;
34

45
/**
56
* Class DateHistogram.
67
*
7-
* @link https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-datehistogram-aggregation.html
8+
* @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-datehistogram-aggregation.html
89
*/
910
class DateHistogram extends Histogram
1011
{
@@ -47,7 +48,7 @@ public function setOffset($offset)
4748
/**
4849
* Set the format for returned bucket key_as_string values.
4950
*
50-
* @link https://www.elastic.co/guide/en/elasticsearch/reference/master/search-aggregations-bucket-daterange-aggregation.html#date-format-pattern
51+
* @see https://www.elastic.co/guide/en/elasticsearch/reference/master/search-aggregations-bucket-daterange-aggregation.html#date-format-pattern
5152
*
5253
* @param string $format see link for formatting options
5354
*
@@ -61,7 +62,7 @@ public function setFormat($format)
6162
/**
6263
* Set extended bounds option.
6364
*
64-
* @link https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-histogram-aggregation.html#search-aggregations-bucket-histogram-aggregation-extended-bounds
65+
* @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-histogram-aggregation.html#search-aggregations-bucket-histogram-aggregation-extended-bounds
6566
*
6667
* @param string $min see link for formatting options
6768
* @param string $max see link for formatting options

lib/Elastica/Aggregation/DateRange.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
<?php
2+
23
namespace Elastica\Aggregation;
34

45
/**
56
* Class DateRange.
67
*
7-
* @link https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-daterange-aggregation.html
8+
* @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-daterange-aggregation.html
89
*/
910
class DateRange extends Range
1011
{

0 commit comments

Comments
 (0)