From 3e302b60ccb106660d3d6aca41c4560def444c28 Mon Sep 17 00:00:00 2001 From: Alexey Kopytko Date: Sat, 30 Sep 2023 12:32:20 +0900 Subject: [PATCH] Improve PHP-CS-Fixer configuration --- .php-cs-fixer.dist.php | 53 ++++++++++++++-------------- src/Helper/RunningVariance.php | 2 ++ src/Standard.php | 3 +- tests/AppendPrependTest.php | 2 ++ tests/ArraysTest.php | 3 ++ tests/Benchmarks/BenchTest.php | 1 + tests/CastTest.php | 3 ++ tests/ChunkTest.php | 1 + tests/CountTest.php | 1 + tests/DocumentationTest.php | 3 +- tests/EagerWithArraysTest.php | 1 + tests/EdgeCasesTest.php | 1 + tests/ErrorsTest.php | 1 + tests/ExampleTest.php | 1 + tests/FlipTest.php | 3 +- tests/FunctionsTest.php | 1 + tests/Helper/RunningVarianceTest.php | 5 +++ tests/IterableTest.php | 1 + tests/LeaguePipelineTest.php | 1 + tests/MapTest.php | 1 + tests/MinMaxTest.php | 3 ++ tests/ReservoirTest.php | 1 + tests/RunningCountTest.php | 1 + tests/SkipWhileTest.php | 1 + tests/SliceTest.php | 3 ++ tests/StandardTest.php | 1 + tests/StaticAnalysisTest.php | 2 +- tests/UnpackTest.php | 1 + tests/VarianceTest.php | 3 ++ tests/ZipTest.php | 1 + 30 files changed, 74 insertions(+), 31 deletions(-) diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 7f4b9a6..b0289a4 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -18,50 +18,49 @@ declare(strict_types=1); $header = <<<'EOF' -Copyright 2017, 2018 Alexey Kopytko + Copyright 2017, 2018 Alexey Kopytko -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() diff --git a/src/Helper/RunningVariance.php b/src/Helper/RunningVariance.php index fba0abb..fde558e 100644 --- a/src/Helper/RunningVariance.php +++ b/src/Helper/RunningVariance.php @@ -21,6 +21,8 @@ use function sqrt; +use const NAN; + /** * Computes statistics (such as standard deviation) in real time. * diff --git a/src/Standard.php b/src/Standard.php index dd97f64..c194a41 100644 --- a/src/Standard.php +++ b/src/Standard.php @@ -27,6 +27,7 @@ use Iterator; use IteratorAggregate; use Traversable; + use function array_chunk; use function array_filter; use function array_flip; @@ -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; } } diff --git a/tests/AppendPrependTest.php b/tests/AppendPrependTest.php index df3be13..b02789c 100644 --- a/tests/AppendPrependTest.php +++ b/tests/AppendPrependTest.php @@ -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; /** diff --git a/tests/ArraysTest.php b/tests/ArraysTest.php index 7f12b91..64f968a 100644 --- a/tests/ArraysTest.php +++ b/tests/ArraysTest.php @@ -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 * diff --git a/tests/Benchmarks/BenchTest.php b/tests/Benchmarks/BenchTest.php index ca0163e..88908cc 100644 --- a/tests/Benchmarks/BenchTest.php +++ b/tests/Benchmarks/BenchTest.php @@ -20,6 +20,7 @@ namespace Tests\Pipeline\Benchmarks; use PHPUnit\Framework\TestCase; + use function array_map; use function array_sum; use function Pipeline\fromArray; diff --git a/tests/CastTest.php b/tests/CastTest.php index 965dec1..b2c438b 100644 --- a/tests/CastTest.php +++ b/tests/CastTest.php @@ -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 * diff --git a/tests/ChunkTest.php b/tests/ChunkTest.php index 727a3bb..50c3c25 100644 --- a/tests/ChunkTest.php +++ b/tests/ChunkTest.php @@ -23,6 +23,7 @@ use IteratorIterator; use PHPUnit\Framework\TestCase; use Pipeline\Standard; + use function Pipeline\fromArray; use function Pipeline\take; diff --git a/tests/CountTest.php b/tests/CountTest.php index 62d2aeb..3b05491 100644 --- a/tests/CountTest.php +++ b/tests/CountTest.php @@ -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; diff --git a/tests/DocumentationTest.php b/tests/DocumentationTest.php index a3a601b..84b65de 100644 --- a/tests/DocumentationTest.php +++ b/tests/DocumentationTest.php @@ -24,6 +24,7 @@ use Pipeline\Standard; use ReflectionClass; use ReflectionMethod; + use function file_get_contents; use function implode; use function Pipeline\take; @@ -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]); diff --git a/tests/EagerWithArraysTest.php b/tests/EagerWithArraysTest.php index ceef00a..b71d698 100644 --- a/tests/EagerWithArraysTest.php +++ b/tests/EagerWithArraysTest.php @@ -23,6 +23,7 @@ use PHPUnit\Framework\TestCase; use Pipeline\Standard; use ReflectionClass; + use function Pipeline\fromArray; use function Pipeline\take; diff --git a/tests/EdgeCasesTest.php b/tests/EdgeCasesTest.php index ee31b9c..ca7342f 100644 --- a/tests/EdgeCasesTest.php +++ b/tests/EdgeCasesTest.php @@ -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; diff --git a/tests/ErrorsTest.php b/tests/ErrorsTest.php index 23f11f0..19eaab5 100644 --- a/tests/ErrorsTest.php +++ b/tests/ErrorsTest.php @@ -24,6 +24,7 @@ use PHPUnit\Framework\TestCase; use Pipeline\Standard; use TypeError; + use function class_exists; use function is_callable; diff --git a/tests/ExampleTest.php b/tests/ExampleTest.php index 70444a8..1c0c7f1 100644 --- a/tests/ExampleTest.php +++ b/tests/ExampleTest.php @@ -20,6 +20,7 @@ namespace Tests\Pipeline; use PHPUnit\Framework\TestCase; + use function ob_end_clean; use function ob_start; diff --git a/tests/FlipTest.php b/tests/FlipTest.php index 0b7fc59..596e870 100644 --- a/tests/FlipTest.php +++ b/tests/FlipTest.php @@ -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; @@ -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]; diff --git a/tests/FunctionsTest.php b/tests/FunctionsTest.php index 1541a44..15f1577 100644 --- a/tests/FunctionsTest.php +++ b/tests/FunctionsTest.php @@ -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; diff --git a/tests/Helper/RunningVarianceTest.php b/tests/Helper/RunningVarianceTest.php index 6aff20a..aaaabed 100644 --- a/tests/Helper/RunningVarianceTest.php +++ b/tests/Helper/RunningVarianceTest.php @@ -22,6 +22,7 @@ use PHPUnit\Framework\TestCase; use Pipeline\Helper\RunningVariance; use Throwable; + use function abs; use function array_sum; use function cos; @@ -33,6 +34,10 @@ use function sin; use function sqrt; +use const NAN; +use const M_PI; +use const PHP_FLOAT_EPSILON; + /** * @internal * diff --git a/tests/IterableTest.php b/tests/IterableTest.php index 62cbf89..60d269b 100644 --- a/tests/IterableTest.php +++ b/tests/IterableTest.php @@ -21,6 +21,7 @@ use PHPUnit\Framework\TestCase; use Pipeline\Standard; + use function iterator_to_array; /** diff --git a/tests/LeaguePipelineTest.php b/tests/LeaguePipelineTest.php index ee9f016..53761f0 100644 --- a/tests/LeaguePipelineTest.php +++ b/tests/LeaguePipelineTest.php @@ -21,6 +21,7 @@ use ArrayIterator; use PHPUnit\Framework\TestCase; + use function iterator_to_array; /** diff --git a/tests/MapTest.php b/tests/MapTest.php index fab5f02..5815735 100644 --- a/tests/MapTest.php +++ b/tests/MapTest.php @@ -20,6 +20,7 @@ namespace Tests\Pipeline; use PHPUnit\Framework\TestCase; + use function Pipeline\map; /** diff --git a/tests/MinMaxTest.php b/tests/MinMaxTest.php index 2c9f8ee..bc32f77 100644 --- a/tests/MinMaxTest.php +++ b/tests/MinMaxTest.php @@ -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; @@ -33,6 +34,8 @@ use function range; use function shuffle; +use const M_E; + /** * @covers \Pipeline\Standard * diff --git a/tests/ReservoirTest.php b/tests/ReservoirTest.php index 1eef213..e1892ad 100644 --- a/tests/ReservoirTest.php +++ b/tests/ReservoirTest.php @@ -23,6 +23,7 @@ use IteratorIterator; use PHPUnit\Framework\TestCase; use Pipeline\Standard; + use function abs; use function mt_rand; use function mt_srand; diff --git a/tests/RunningCountTest.php b/tests/RunningCountTest.php index 2f4fbda..d39e714 100644 --- a/tests/RunningCountTest.php +++ b/tests/RunningCountTest.php @@ -20,6 +20,7 @@ namespace Tests\Pipeline; use PHPUnit\Framework\TestCase; + use function Pipeline\map; use function Pipeline\take; use function range; diff --git a/tests/SkipWhileTest.php b/tests/SkipWhileTest.php index 6f6a500..2637f8b 100644 --- a/tests/SkipWhileTest.php +++ b/tests/SkipWhileTest.php @@ -21,6 +21,7 @@ use PHPUnit\Framework\TestCase; use Pipeline\Standard; + use function Pipeline\map; use function Pipeline\take; diff --git a/tests/SliceTest.php b/tests/SliceTest.php index 756d78f..2199496 100644 --- a/tests/SliceTest.php +++ b/tests/SliceTest.php @@ -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; @@ -34,6 +35,8 @@ use function Pipeline\take; use function range; +use const PHP_INT_MAX; + /** * @covers \Pipeline\Standard * diff --git a/tests/StandardTest.php b/tests/StandardTest.php index 8d8364f..8918c5e 100644 --- a/tests/StandardTest.php +++ b/tests/StandardTest.php @@ -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; diff --git a/tests/StaticAnalysisTest.php b/tests/StaticAnalysisTest.php index e314e6b..124dbff 100644 --- a/tests/StaticAnalysisTest.php +++ b/tests/StaticAnalysisTest.php @@ -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) diff --git a/tests/UnpackTest.php b/tests/UnpackTest.php index 458354e..db44ca7 100644 --- a/tests/UnpackTest.php +++ b/tests/UnpackTest.php @@ -21,6 +21,7 @@ use ArrayIterator; use PHPUnit\Framework\TestCase; + use function Pipeline\fromArray; use function round; use function sqrt; diff --git a/tests/VarianceTest.php b/tests/VarianceTest.php index 4acc191..b619ca4 100644 --- a/tests/VarianceTest.php +++ b/tests/VarianceTest.php @@ -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() diff --git a/tests/ZipTest.php b/tests/ZipTest.php index fe3eda4..4091ddd 100644 --- a/tests/ZipTest.php +++ b/tests/ZipTest.php @@ -22,6 +22,7 @@ use ArrayIterator; use PHPUnit\Framework\TestCase; use Pipeline\Standard; + use function array_map; use function max; use function Pipeline\fromArray;