Skip to content

Commit

Permalink
Improve PHP-CS-Fixer configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
sanmai committed Sep 30, 2023
1 parent 2e88e46 commit 3e302b6
Show file tree
Hide file tree
Showing 30 changed files with 74 additions and 31 deletions.
53 changes: 26 additions & 27 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,50 +18,49 @@
declare(strict_types=1);

$header = <<<'EOF'
Copyright 2017, 2018 Alexey Kopytko <alexey@kopytko.com>
Copyright 2017, 2018 Alexey Kopytko <alexey@kopytko.com>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
EOF;
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
EOF;

$config = new PhpCsFixer\Config();
$config
->setRiskyAllowed(true)
->setRules([
'header_comment' => ['comment_type' => 'PHPDoc', 'header' => $header, 'separate' => 'bottom', 'location' => 'after_open'],
'@PER-CS' => true,
'@PER-CS:risky' => true,

'@Symfony:risky' => true,
'@PHP71Migration:risky' => true,
'@PHPUnit75Migration:risky' => true,
'@PhpCsFixer' => true,
'@PhpCsFixer:risky' => true,
'@PHPUnit100Migration:risky' => true,
'@PHP74Migration' => true,

'ordered_class_elements' => false,
'phpdoc_to_comment' => false,
'strict_comparison' => true,
'comment_to_phpdoc' => true,
'native_function_invocation' => ['include' => ['@internal'], 'scope' => 'namespaced'],
'native_constant_invocation' => [
'strict' => false,
'scope' => 'namespaced',
],
'native_function_invocation' => [
'include' => ['@internal'],
'scope' => 'namespaced',
],
'global_namespace_import' => [
'import_classes' => true,
'import_constants' => true,
'import_functions' => true,
],
'php_unit_test_case_static_method_calls' => false,

'strict_comparison' => true,
'yoda_style' => true,
'random_api_migration' => false,
'blank_line_between_import_groups' => false,
'blank_line_before_statement' => ['statements' => ['break', 'continue', 'declare', 'return', 'throw', 'try']],
'no_unset_on_property' => false,
'multiline_whitespace_before_semicolons' => false,
'array_indentation' => true,
])
->setFinder(
PhpCsFixer\Finder::create()
Expand Down
2 changes: 2 additions & 0 deletions src/Helper/RunningVariance.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

use function sqrt;

use const NAN;

/**
* Computes statistics (such as standard deviation) in real time.
*
Expand Down
3 changes: 2 additions & 1 deletion src/Standard.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use Iterator;
use IteratorAggregate;
use Traversable;

use function array_chunk;
use function array_filter;
use function array_flip;
Expand Down Expand Up @@ -749,7 +750,7 @@ private static function tail(iterable $input, int $length): Generator
$buffer[] = [$key, $value];
}

foreach ($buffer as list($key, $value)) {
foreach ($buffer as [$key, $value]) {
yield $key => $value;
}
}
Expand Down
2 changes: 2 additions & 0 deletions tests/AppendPrependTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@

use ArrayIterator;
use PHPUnit\Framework\TestCase;

use function count;
use function is_numeric;
use function key;
use function Pipeline\take;
use function reset;

use const PHP_VERSION_ID;

/**
Expand Down
3 changes: 3 additions & 0 deletions tests/ArraysTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@
use PHPUnit\Framework\TestCase;
use Pipeline\Standard;
use ReflectionObject;

use function iterator_to_array;

use const PHP_INT_MAX;

/**
* @covers \Pipeline\Standard
*
Expand Down
1 change: 1 addition & 0 deletions tests/Benchmarks/BenchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
namespace Tests\Pipeline\Benchmarks;

use PHPUnit\Framework\TestCase;

use function array_map;
use function array_sum;
use function Pipeline\fromArray;
Expand Down
3 changes: 3 additions & 0 deletions tests/CastTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@
use Generator;
use PHPUnit\Framework\TestCase;
use Pipeline\Standard;

use function Pipeline\map;
use function Pipeline\take;

use const M_PI;

/**
* @covers \Pipeline\Standard
*
Expand Down
1 change: 1 addition & 0 deletions tests/ChunkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use IteratorIterator;
use PHPUnit\Framework\TestCase;
use Pipeline\Standard;

use function Pipeline\fromArray;
use function Pipeline\take;

Expand Down
1 change: 1 addition & 0 deletions tests/CountTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use ArrayIterator;
use PHPUnit\Framework\TestCase;
use Pipeline\Standard;

use function Pipeline\fromArray;
use function Pipeline\map;
use function Pipeline\take;
Expand Down
3 changes: 2 additions & 1 deletion tests/DocumentationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use Pipeline\Standard;
use ReflectionClass;
use ReflectionMethod;

use function file_get_contents;
use function implode;
use function Pipeline\take;
Expand All @@ -48,7 +49,7 @@ final class DocumentationTest extends TestCase

public static function setUpBeforeClass(): void
{
self::$readme = file_get_contents(__DIR__.'/../README.md');
self::$readme = file_get_contents(__DIR__ . '/../README.md');

preg_match_all('/^#.*/m', self::$readme, $matches);
self::$headers = implode("\n", $matches[0]);
Expand Down
1 change: 1 addition & 0 deletions tests/EagerWithArraysTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use PHPUnit\Framework\TestCase;
use Pipeline\Standard;
use ReflectionClass;

use function Pipeline\fromArray;
use function Pipeline\take;

Expand Down
1 change: 1 addition & 0 deletions tests/EdgeCasesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use NoRewindIterator;
use PHPUnit\Framework\TestCase;
use Pipeline\Standard;

use function iterator_to_array;
use function Pipeline\map;
use function range;
Expand Down
1 change: 1 addition & 0 deletions tests/ErrorsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use PHPUnit\Framework\TestCase;
use Pipeline\Standard;
use TypeError;

use function class_exists;
use function is_callable;

Expand Down
1 change: 1 addition & 0 deletions tests/ExampleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
namespace Tests\Pipeline;

use PHPUnit\Framework\TestCase;

use function ob_end_clean;
use function ob_start;

Expand Down
3 changes: 2 additions & 1 deletion tests/FlipTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use IteratorIterator;
use PHPUnit\Framework\TestCase;
use Pipeline\Standard;

use function array_flip;
use function array_reverse;
use function call_user_func;
Expand Down Expand Up @@ -80,7 +81,7 @@ private static function provideInputs(): iterable
'two' => 'string_key2',
'' => 'string_key3',
' ' => 'string_key4',
'a'.chr(0).'b' => 'binary_key1',
'a' . chr(0) . 'b' => 'binary_key1',
];

yield [1 => 'value', 2 => 'VALUE', 3 => 4];
Expand Down
1 change: 1 addition & 0 deletions tests/FunctionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use ArrayIterator;
use PHPUnit\Framework\TestCase;
use Pipeline\Standard;

use function array_map;
use function iterator_to_array;
use function Pipeline\fromArray;
Expand Down
5 changes: 5 additions & 0 deletions tests/Helper/RunningVarianceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use PHPUnit\Framework\TestCase;
use Pipeline\Helper\RunningVariance;
use Throwable;

use function abs;
use function array_sum;
use function cos;
Expand All @@ -33,6 +34,10 @@
use function sin;
use function sqrt;

use const NAN;
use const M_PI;
use const PHP_FLOAT_EPSILON;

/**
* @internal
*
Expand Down
1 change: 1 addition & 0 deletions tests/IterableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

use PHPUnit\Framework\TestCase;
use Pipeline\Standard;

use function iterator_to_array;

/**
Expand Down
1 change: 1 addition & 0 deletions tests/LeaguePipelineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

use ArrayIterator;
use PHPUnit\Framework\TestCase;

use function iterator_to_array;

/**
Expand Down
1 change: 1 addition & 0 deletions tests/MapTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
namespace Tests\Pipeline;

use PHPUnit\Framework\TestCase;

use function Pipeline\map;

/**
Expand Down
3 changes: 3 additions & 0 deletions tests/MinMaxTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use IteratorIterator;
use PHPUnit\Framework\TestCase;
use Pipeline\Standard;

use function array_merge;
use function array_reverse;
use function call_user_func;
Expand All @@ -33,6 +34,8 @@
use function range;
use function shuffle;

use const M_E;

/**
* @covers \Pipeline\Standard
*
Expand Down
1 change: 1 addition & 0 deletions tests/ReservoirTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use IteratorIterator;
use PHPUnit\Framework\TestCase;
use Pipeline\Standard;

use function abs;
use function mt_rand;
use function mt_srand;
Expand Down
1 change: 1 addition & 0 deletions tests/RunningCountTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
namespace Tests\Pipeline;

use PHPUnit\Framework\TestCase;

use function Pipeline\map;
use function Pipeline\take;
use function range;
Expand Down
1 change: 1 addition & 0 deletions tests/SkipWhileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

use PHPUnit\Framework\TestCase;
use Pipeline\Standard;

use function Pipeline\map;
use function Pipeline\take;

Expand Down
3 changes: 3 additions & 0 deletions tests/SliceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use PHPUnit\Framework\TestCase;
use Pipeline\Standard;
use RuntimeException;

use function array_merge;
use function array_slice;
use function array_values;
Expand All @@ -34,6 +35,8 @@
use function Pipeline\take;
use function range;

use const PHP_INT_MAX;

/**
* @covers \Pipeline\Standard
*
Expand Down
1 change: 1 addition & 0 deletions tests/StandardTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use PHPUnit\Framework\TestCase;
use Pipeline\Standard;
use ReflectionClass;

use function call_user_func;
use function iterator_count;
use function iterator_to_array;
Expand Down
2 changes: 1 addition & 1 deletion tests/StaticAnalysisTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function testAllMethodsArePublicOrPrivate(ReflectionMethod $method): void
*/
public function testInterfaceCompatibilityPHP71(): void
{
$example = new class() extends Standard {
$example = new class () extends Standard {
private $input;

public function __construct(iterable $input = null)
Expand Down
1 change: 1 addition & 0 deletions tests/UnpackTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

use ArrayIterator;
use PHPUnit\Framework\TestCase;

use function Pipeline\fromArray;
use function round;
use function sqrt;
Expand Down
3 changes: 3 additions & 0 deletions tests/VarianceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@

use PHPUnit\Framework\TestCase;
use Pipeline\Helper\RunningVariance;

use function Pipeline\fromArray;
use function Pipeline\map;

use const NAN;

/**
* @covers \Pipeline\Standard::feedRunningVariance()
* @covers \Pipeline\Standard::finalVariance()
Expand Down
1 change: 1 addition & 0 deletions tests/ZipTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use ArrayIterator;
use PHPUnit\Framework\TestCase;
use Pipeline\Standard;

use function array_map;
use function max;
use function Pipeline\fromArray;
Expand Down

0 comments on commit 3e302b6

Please sign in to comment.