Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Base PHP-cs-fixer migration to version 2 plus style fix #1555

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
44 changes: 19 additions & 25 deletions .php_cs
Original file line number Diff line number Diff line change
@@ -1,32 +1,26 @@
<?php

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

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

return $config;
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ env:
- TARGET="71"
- TARGET="72"
- TARGET="73"
- TARGET="Lint"

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

script:
- make tests TARGET=$TARGET
- if [ "$TARGET" != "Lint" ] ; then make tests TARGET=$TARGET ; fi
- if [ "$TARGET" == "Lint" ] ; then make check-style ; fi

after_script:
- cat /var/log/elasticsearch/*.log
Expand Down
15 changes: 12 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ tests:
make start
mkdir -p build

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

# Makes it easy to run a single test file. Example to run IndexTest.php: make test TEST="IndexTest.php"
Expand All @@ -79,7 +79,16 @@ doc:
# Uses the preconfigured standards in .php_cs
.PHONY: lint
lint:
${RUN_ENV} php-cs-fixer fix
${RUN_ENV} php-cs-fixer fix --allow-risky=yes

.PHONY: check-style
check-style:
docker build -t ruflin/elastica-dev-base -f env/elastica/${TARGET} env/elastica/
docker build -t ruflin/elastica .
make start
mkdir -p build

${RUN_ENV} php-cs-fixer fix --allow-risky=yes --dry-run

.PHONY: loc
loc:
Expand Down Expand Up @@ -140,7 +149,7 @@ gource:

## DOCKER IMAGES

.PHONY: elastica-image
.PHONY: elastica-image
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this change intentional?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I didn't notice that 🤔
Fixing..

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still needs a fix ;-)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed 😄

elastica-image:
docker build -t ruflin/elastica-dev-base -f env/elastica/Docker${TARGET} env/elastica/
docker build -t ruflin/elastica .
Expand Down
39 changes: 39 additions & 0 deletions env/elastica/Lint
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# This image is the base image for the Elastica development and includes all parts which rarely change
# PHP 7 Docker file with Composer installed
FROM php:7.2
MAINTAINER Nicolas Ruflin <[email protected]>

RUN apt-get update && apt-get install -y \
cloc \
git \
graphviz \
libxslt-dev \
nano \
zip unzip \
wget
# XSL and Graphviz for PhpDocumentor

RUN docker-php-ext-install sockets xsl

RUN rm -r /var/lib/apt/lists/*

# Xdebug for coverage report
RUN pecl install xdebug-2.6.1

RUN echo "memory_limit=1024M" >> /usr/local/etc/php/conf.d/memory-limit.ini
RUN echo "date.timezone=UTC" >> /usr/local/etc/php/conf.d/timezone.ini

# Install and setup composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
ENV COMPOSER_HOME /root/composer

# Add composer bin to the environment
ENV PATH=/root/composer/vendor/bin:$PATH

COPY composer.json /root/composer/

RUN composer global remove --no-update phpdocumentor/phpdocumentor -vvv
RUN composer global require --no-update friendsofphp/php-cs-fixer:^2.0

# Install development tools, prefer source removed as automatic fallback now
RUN composer global install -vvv
3 changes: 1 addition & 2 deletions env/elastica/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"require": {
"php": "^7.0",
"phpdocumentor/phpdocumentor": "^2.9",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we please keep this in? I need this to generate the docs :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok :) Probably I forgot to readd that one.

"fabpot/php-cs-fixer": "1.11.*",
"mayflower/php-codebrowser": "~1.1",
"pdepend/pdepend": "^2.5",
"phploc/phploc": "^4.0",
Expand All @@ -23,4 +22,4 @@
"sebastian/phpcpd": "~3.0",
"squizlabs/php_codesniffer": "~3.3"
}
}
}
5 changes: 3 additions & 2 deletions lib/Elastica/AbstractUpdateAction.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Elastica;

/**
Expand Down Expand Up @@ -108,7 +109,7 @@ public function getIndex()
*
* @return $this
*
* @link https://www.elastic.co/blog/versioning
* @see https://www.elastic.co/blog/versioning
*/
public function setVersion($version)
{
Expand Down Expand Up @@ -171,7 +172,7 @@ public function hasVersionType()
*
* @return $this
*
* @link https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-parent-field.html
* @see https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-parent-field.html
*/
public function setParent($parent)
{
Expand Down
1 change: 1 addition & 0 deletions lib/Elastica/Aggregation/AbstractAggregation.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Elastica\Aggregation;

use Elastica\Exception\InvalidException;
Expand Down
1 change: 1 addition & 0 deletions lib/Elastica/Aggregation/AbstractSimpleAggregation.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Elastica\Aggregation;

use Elastica\Exception\InvalidException;
Expand Down
5 changes: 3 additions & 2 deletions lib/Elastica/Aggregation/AbstractTermsAggregation.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Elastica\Aggregation;

/**
Expand Down Expand Up @@ -61,7 +62,7 @@ public function setExclude($pattern, $flags = null)
/**
* Sets the amount of terms to be returned.
*
* @param int $size The amount of terms to be returned.
* @param int $size the amount of terms to be returned
*
* @return $this
*/
Expand All @@ -73,7 +74,7 @@ public function setSize($size)
/**
* Sets how many terms the coordinating node will request from each shard.
*
* @param int $shard_size The amount of terms to be returned.
* @param int $shard_size the amount of terms to be returned
*
* @return $this
*/
Expand Down
3 changes: 2 additions & 1 deletion lib/Elastica/Aggregation/Avg.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?php

namespace Elastica\Aggregation;

/**
* Class Avg.
*
* @link https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-avg-aggregation.html
* @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-avg-aggregation.html
*/
class Avg extends AbstractSimpleAggregation
{
Expand Down
5 changes: 3 additions & 2 deletions lib/Elastica/Aggregation/AvgBucket.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<?php

namespace Elastica\Aggregation;

use Elastica\Exception\InvalidException;

/**
* Class AvgBucket.
*
* @link https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-avg-bucket-aggregation.html
* @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-avg-bucket-aggregation.html
*/
class AvgBucket extends AbstractAggregation
{
Expand All @@ -18,7 +19,7 @@ public function __construct($name, $bucketsPath = null)
{
parent::__construct($name);

if ($bucketsPath !== null) {
if (null !== $bucketsPath) {
$this->setBucketsPath($bucketsPath);
}
}
Expand Down
7 changes: 4 additions & 3 deletions lib/Elastica/Aggregation/BucketScript.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<?php

namespace Elastica\Aggregation;

use Elastica\Exception\InvalidException;

/**
* Class BucketScript.
*
* @link https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-bucket-script-aggregation.html
* @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-bucket-script-aggregation.html
*/
class BucketScript extends AbstractAggregation
{
Expand All @@ -19,11 +20,11 @@ public function __construct($name, $bucketsPath = null, $script = null)
{
parent::__construct($name);

if ($bucketsPath !== null) {
if (null !== $bucketsPath) {
$this->setBucketsPath($bucketsPath);
}

if ($script !== null) {
if (null !== $script) {
$this->setScript($script);
}
}
Expand Down
9 changes: 5 additions & 4 deletions lib/Elastica/Aggregation/BucketSelector.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<?php

namespace Elastica\Aggregation;

/**
* Class BucketSelector.
* @link https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-bucket-selector-aggregation.html
*
* @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-bucket-selector-aggregation.html
*/
class BucketSelector extends AbstractSimpleAggregation
{
Expand All @@ -16,11 +18,11 @@ public function __construct(string $name, array $bucketsPath = null, string $scr
{
parent::__construct($name);

if ($bucketsPath !== null) {
if (null !== $bucketsPath) {
$this->setBucketsPath($bucketsPath);
}

if ($script !== null) {
if (null !== $script) {
$this->setScript($script);
}
}
Expand Down Expand Up @@ -49,4 +51,3 @@ public function setGapPolicy(string $gapPolicy = 'skip')
return $this->setParam('gap_policy', $gapPolicy);
}
}

3 changes: 2 additions & 1 deletion lib/Elastica/Aggregation/Cardinality.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?php

namespace Elastica\Aggregation;

/**
* Class Cardinality.
*
* @link https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-cardinality-aggregation.html
* @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-cardinality-aggregation.html
*/
class Cardinality extends AbstractSimpleAggregation
{
Expand Down
3 changes: 2 additions & 1 deletion lib/Elastica/Aggregation/Children.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?php

namespace Elastica\Aggregation;

/**
* Class Children.
*
* @link https://www.elastic.co/guide/en/elasticsearch/reference/1.7/search-aggregations-bucket-children-aggregation.html
* @see https://www.elastic.co/guide/en/elasticsearch/reference/1.7/search-aggregations-bucket-children-aggregation.html
*/
class Children extends AbstractAggregation
{
Expand Down
7 changes: 4 additions & 3 deletions lib/Elastica/Aggregation/DateHistogram.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?php

namespace Elastica\Aggregation;

/**
* Class DateHistogram.
*
* @link https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-datehistogram-aggregation.html
* @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-datehistogram-aggregation.html
*/
class DateHistogram extends Histogram
{
Expand Down Expand Up @@ -47,7 +48,7 @@ public function setOffset($offset)
/**
* Set the format for returned bucket key_as_string values.
*
* @link https://www.elastic.co/guide/en/elasticsearch/reference/master/search-aggregations-bucket-daterange-aggregation.html#date-format-pattern
* @see https://www.elastic.co/guide/en/elasticsearch/reference/master/search-aggregations-bucket-daterange-aggregation.html#date-format-pattern
*
* @param string $format see link for formatting options
*
Expand All @@ -61,7 +62,7 @@ public function setFormat($format)
/**
* Set extended bounds option.
*
* @link https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-histogram-aggregation.html#search-aggregations-bucket-histogram-aggregation-extended-bounds
* @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-histogram-aggregation.html#search-aggregations-bucket-histogram-aggregation-extended-bounds
*
* @param string $min see link for formatting options
* @param string $max see link for formatting options
Expand Down
3 changes: 2 additions & 1 deletion lib/Elastica/Aggregation/DateRange.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?php

namespace Elastica\Aggregation;

/**
* Class DateRange.
*
* @link https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-daterange-aggregation.html
* @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-daterange-aggregation.html
*/
class DateRange extends Range
{
Expand Down
Loading