From 11e4804e7a6ecbb46fa7d3b365e3e60cbc2f8293 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Sat, 30 Sep 2023 11:22:30 +0200 Subject: [PATCH 1/2] Enhancement: Require ergebnis/rector-rules --- composer.json | 1 + composer.lock | 226 ++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 220 insertions(+), 7 deletions(-) diff --git a/composer.json b/composer.json index 4d32fa5d..57812da3 100644 --- a/composer.json +++ b/composer.json @@ -28,6 +28,7 @@ "ergebnis/data-provider": "^3.0.0", "ergebnis/license": "^2.2.0", "ergebnis/phpunit-slow-test-detector": "^2.3.0", + "ergebnis/rector-rules": "~0.1.0", "fakerphp/faker": "^1.23.0", "phpunit/phpunit": "^10.3.5", "psalm/plugin-phpunit": "~0.18.4", diff --git a/composer.lock b/composer.lock index 8043b533..e8784a78 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "38f15c10d085d9f043a75698f9294042", + "content-hash": "ccb2e53ee0de0854b557cd188c2db81f", "packages": [ { "name": "composer/pcre", @@ -2848,6 +2848,72 @@ }, "time": "2023-05-30T17:23:26+00:00" }, + { + "name": "ergebnis/rector-rules", + "version": "0.1.0", + "source": { + "type": "git", + "url": "https://github.com/ergebnis/rector-rules.git", + "reference": "77926eedabc0c5de0aa676e2c5449b76d851b861" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/ergebnis/rector-rules/zipball/77926eedabc0c5de0aa676e2c5449b76d851b861", + "reference": "77926eedabc0c5de0aa676e2c5449b76d851b861", + "shasum": "" + }, + "require": { + "nikic/php-parser": "^4.17.1", + "php": "~8.1.0 || ~8.2.0", + "phpstan/phpstan": "^1.10.36", + "rector/rector": "~0.18.4", + "symplify/rule-doc-generator-contracts": "^11.1.26" + }, + "require-dev": { + "ergebnis/composer-normalize": "^2.37.0", + "ergebnis/data-provider": "^3.0.0", + "ergebnis/license": "^2.2.0", + "ergebnis/php-cs-fixer-config": "^6.6.0", + "ergebnis/phpstan-rules": "^2.1.0", + "ergebnis/phpunit-slow-test-detector": "^2.3.0", + "fakerphp/faker": "^1.23.0", + "infection/infection": "~0.27.3", + "phpunit/phpunit": "^10.3.5", + "psalm/plugin-phpunit": "~0.18.4", + "vimeo/psalm": "^5.15.0" + }, + "type": "library", + "extra": { + "composer-normalize": { + "indent-size": 2, + "indent-style": "space" + } + }, + "autoload": { + "psr-4": { + "Ergebnis\\Rector\\Rules\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Andreas Möller", + "email": "am@localheinz.com", + "homepage": "https://localheinz.com" + } + ], + "description": "Provides a GitHub repository template for a PHP package with GitHub Actions workflows using standard PHP development tools.", + "homepage": "https://github.com/ergebnis/rector-rules", + "support": { + "issues": "https://github.com/ergebnis/rector-rules/issues", + "security": "https://github.com/ergebnis/rector-rules/blob/main/.github/SECURITY.md", + "source": "https://github.com/ergebnis/rector-rules" + }, + "time": "2023-09-30T09:17:14+00:00" + }, { "name": "fakerphp/faker", "version": "v1.23.0", @@ -3318,6 +3384,92 @@ }, "time": "2023-04-09T17:37:40+00:00" }, + { + "name": "nette/utils", + "version": "v3.2.10", + "source": { + "type": "git", + "url": "https://github.com/nette/utils.git", + "reference": "a4175c62652f2300c8017fb7e640f9ccb11648d2" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/nette/utils/zipball/a4175c62652f2300c8017fb7e640f9ccb11648d2", + "reference": "a4175c62652f2300c8017fb7e640f9ccb11648d2", + "shasum": "" + }, + "require": { + "php": ">=7.2 <8.4" + }, + "conflict": { + "nette/di": "<3.0.6" + }, + "require-dev": { + "jetbrains/phpstorm-attributes": "dev-master", + "nette/tester": "~2.0", + "phpstan/phpstan": "^1.0", + "tracy/tracy": "^2.3" + }, + "suggest": { + "ext-gd": "to use Image", + "ext-iconv": "to use Strings::webalize(), toAscii(), chr() and reverse()", + "ext-intl": "to use Strings::webalize(), toAscii(), normalize() and compare()", + "ext-json": "to use Nette\\Utils\\Json", + "ext-mbstring": "to use Strings::lower() etc...", + "ext-tokenizer": "to use Nette\\Utils\\Reflection::getUseStatements()", + "ext-xml": "to use Strings::length() etc. when mbstring is not available" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.2-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause", + "GPL-2.0-only", + "GPL-3.0-only" + ], + "authors": [ + { + "name": "David Grudl", + "homepage": "https://davidgrudl.com" + }, + { + "name": "Nette Community", + "homepage": "https://nette.org/contributors" + } + ], + "description": "🛠 Nette Utils: lightweight utilities for string & array manipulation, image handling, safe JSON encoding/decoding, validation, slug or strong password generating etc.", + "homepage": "https://nette.org", + "keywords": [ + "array", + "core", + "datetime", + "images", + "json", + "nette", + "paginator", + "password", + "slugify", + "string", + "unicode", + "utf-8", + "utility", + "validation" + ], + "support": { + "issues": "https://github.com/nette/utils/issues", + "source": "https://github.com/nette/utils/tree/v3.2.10" + }, + "time": "2023-07-30T15:38:18+00:00" + }, { "name": "nikic/php-parser", "version": "v4.17.1", @@ -3702,16 +3854,16 @@ }, { "name": "phpstan/phpstan", - "version": "1.10.35", + "version": "1.10.36", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "e730e5facb75ffe09dfb229795e8c01a459f26c3" + "reference": "ffa3089511121a672e62969404e4fddc753f9b15" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/e730e5facb75ffe09dfb229795e8c01a459f26c3", - "reference": "e730e5facb75ffe09dfb229795e8c01a459f26c3", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/ffa3089511121a672e62969404e4fddc753f9b15", + "reference": "ffa3089511121a672e62969404e4fddc753f9b15", "shasum": "" }, "require": { @@ -3760,7 +3912,7 @@ "type": "tidelift" } ], - "time": "2023-09-19T15:27:56+00:00" + "time": "2023-09-29T14:07:45+00:00" }, { "name": "phpunit/php-code-coverage", @@ -5211,6 +5363,66 @@ ], "time": "2023-07-19T18:30:26+00:00" }, + { + "name": "symplify/rule-doc-generator-contracts", + "version": "11.1.26", + "source": { + "type": "git", + "url": "https://github.com/symplify/rule-doc-generator-contracts.git", + "reference": "3e66b3fec678b74a076395ec629d535fb95293b5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symplify/rule-doc-generator-contracts/zipball/3e66b3fec678b74a076395ec629d535fb95293b5", + "reference": "3e66b3fec678b74a076395ec629d535fb95293b5", + "shasum": "" + }, + "require": { + "nette/utils": "^3.2", + "php": ">=8.1" + }, + "require-dev": { + "php-parallel-lint/php-parallel-lint": "^1.3", + "phpstan/extension-installer": "^1.2", + "rector/rector": "^0.15.10", + "symplify/easy-ci": "^11.1", + "symplify/easy-coding-standard": "^11.1", + "symplify/easy-testing": "^11.1", + "symplify/phpstan-extensions": "^11.1", + "symplify/phpstan-rules": "11.2.3.72", + "tomasvotruba/unused-public": "^0.0.34" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "11.2-dev" + } + }, + "autoload": { + "psr-4": { + "Symplify\\RuleDocGenerator\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Contracts for production code of RuleDocGenerator", + "support": { + "source": "https://github.com/symplify/rule-doc-generator-contracts/tree/11.1.26" + }, + "funding": [ + { + "url": "https://www.paypal.me/rectorphp", + "type": "custom" + }, + { + "url": "https://github.com/tomasvotruba", + "type": "github" + } + ], + "time": "2023-02-07T07:16:13+00:00" + }, { "name": "theseer/tokenizer", "version": "1.2.1", @@ -5442,5 +5654,5 @@ "platform-overrides": { "php": "8.1.20" }, - "plugin-api-version": "2.3.0" + "plugin-api-version": "2.6.0" } From 3dc40bb3e4fba6a4b5c9e3a3dabf1a77a5163e1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Sat, 30 Sep 2023 11:24:22 +0200 Subject: [PATCH 2/2] Enhancement: Use Rules\Arrays\SortAssociativeArrayByKeyRector --- .php-cs-fixer.php | 1 - psalm-baseline.xml | 5 - psalm.xml | 4 +- rector.php | 8 +- .../SortAssociativeArrayByKey/class.php.inc | 47 ------- .../SortAssociativeArrayByKey/file.php.inc | 35 ----- .../SortAssociativeArrayByKey/test.php.inc | 51 ------- test/Rector/SortAssociativeArrayByKey.php | 130 ------------------ .../SortAssociativeArrayByKeyTest.php | 38 ----- .../config/configured_rule.php | 19 --- 10 files changed, 4 insertions(+), 334 deletions(-) delete mode 100644 test/Fixture/Rector/SortAssociativeArrayByKey/class.php.inc delete mode 100644 test/Fixture/Rector/SortAssociativeArrayByKey/file.php.inc delete mode 100644 test/Fixture/Rector/SortAssociativeArrayByKey/test.php.inc delete mode 100644 test/Rector/SortAssociativeArrayByKey.php delete mode 100644 test/Unit/Rector/SortAssociativeArrayByKey/SortAssociativeArrayByKeyTest.php delete mode 100644 test/Unit/Rector/SortAssociativeArrayByKey/config/configured_rule.php diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php index 970fedb0..7e414e4f 100644 --- a/.php-cs-fixer.php +++ b/.php-cs-fixer.php @@ -35,7 +35,6 @@ '.build/', '.github/', '.note/', - 'test/Fixture/', ]) ->ignoreDotFiles(false) ->in(__DIR__); diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 042587f2..86a3ceb0 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -104,11 +104,6 @@ provideValueGreaterThanNinetyNine - - - provideData - - new FixerFactory() diff --git a/psalm.xml b/psalm.xml index 923eaf93..00713658 100644 --- a/psalm.xml +++ b/psalm.xml @@ -18,9 +18,7 @@ - - - + diff --git a/rector.php b/rector.php index cb59ced6..7667b2bf 100644 --- a/rector.php +++ b/rector.php @@ -11,7 +11,7 @@ * @see https://github.com/ergebnis/php-cs-fixer-config */ -use Ergebnis\PhpCsFixer; +use Ergebnis\Rector\Rules; use Rector\Config; use Rector\Core; use Rector\Php81; @@ -24,16 +24,14 @@ $rectorConfig->paths([ __DIR__ . '/src/', - __DIR__ . '/test/EndToEnd/', - __DIR__ . '/test/Unit/', - __DIR__ . '/test/Util/', + __DIR__ . '/test/', ]); $rectorConfig->phpVersion(Core\ValueObject\PhpVersion::PHP_81); $rectorConfig->rules([ Php81\Rector\Property\ReadOnlyPropertyRector::class, - PhpCsFixer\Config\Test\Rector\SortAssociativeArrayByKey::class, + Rules\Arrays\SortAssociativeArrayByKeyRector::class, ]); $rectorConfig->sets([ diff --git a/test/Fixture/Rector/SortAssociativeArrayByKey/class.php.inc b/test/Fixture/Rector/SortAssociativeArrayByKey/class.php.inc deleted file mode 100644 index d1dd93e3..00000000 --- a/test/Fixture/Rector/SortAssociativeArrayByKey/class.php.inc +++ /dev/null @@ -1,47 +0,0 @@ - [ - 'foo', - 'bar', - 'baz', - ], - 'bar' => [ - 'quz' => 'qux', - 'quux' => 'quuz', - ], - ]; - } -} - -?> ------ - [ - 'quux' => 'quuz', - 'quz' => 'qux', - ], - 'foo' => [ - 'foo', - 'bar', - 'baz', - ], - ]; - } -} - -?> diff --git a/test/Fixture/Rector/SortAssociativeArrayByKey/file.php.inc b/test/Fixture/Rector/SortAssociativeArrayByKey/file.php.inc deleted file mode 100644 index ba6e9155..00000000 --- a/test/Fixture/Rector/SortAssociativeArrayByKey/file.php.inc +++ /dev/null @@ -1,35 +0,0 @@ - [ - 'foo', - 'bar', - 'baz', - ], - 'bar' => [ - 'quz' => 'qux', - 'quux' => 'quuz', - ], -]; - -?> ------ - [ - 'quux' => 'quuz', - 'quz' => 'qux', - ], - 'foo' => [ - 'foo', - 'bar', - 'baz', - ], -]; - -?> diff --git a/test/Fixture/Rector/SortAssociativeArrayByKey/test.php.inc b/test/Fixture/Rector/SortAssociativeArrayByKey/test.php.inc deleted file mode 100644 index 03d36048..00000000 --- a/test/Fixture/Rector/SortAssociativeArrayByKey/test.php.inc +++ /dev/null @@ -1,51 +0,0 @@ - [ - 'foo', - 'bar', - 'baz', - ], - 'bar' => [ - 'quz' => 'qux', - 'quux' => 'quuz', - ], - ]; - } -} - -?> ------ - [ - 'foo', - 'bar', - 'baz', - ], - 'bar' => [ - 'quz' => 'qux', - 'quux' => 'quuz', - ], - ]; - } -} - -?> diff --git a/test/Rector/SortAssociativeArrayByKey.php b/test/Rector/SortAssociativeArrayByKey.php deleted file mode 100644 index 34d5652d..00000000 --- a/test/Rector/SortAssociativeArrayByKey.php +++ /dev/null @@ -1,130 +0,0 @@ - 1, - 'bar' => 2, -]; -CODE_SAMPLE - , - <<<'CODE_SAMPLE' -$item = [ - 'bar' => 2, - 'foo' => 1, -]; -CODE_SAMPLE - ), - ], - ); - } - - public function getNodeTypes(): array - { - return [ - Node\Expr\Array_::class, - ]; - } - - public function refactor(Node $node): ?Node - { - if (!$node instanceof Node\Expr\Array_) { - return null; - } - - if ($this->isScopeInTest($node)) { - return null; - } - - /** @var array $items */ - $items = \array_filter($node->items, static function ($item): bool { - if (!$item instanceof Node\Expr\ArrayItem) { - return false; - } - - if (!$item->key instanceof Node\Scalar\String_) { - return false; - } - - return true; - }); - - if ($items !== $node->items) { - return null; - } - - \usort($items, static function (Node\Expr\ArrayItem $a, Node\Expr\ArrayItem $b): int { - if (!$a->key instanceof Node\Scalar\String_) { - throw new \RuntimeException('This should not happen.'); - } - - if (!$b->key instanceof Node\Scalar\String_) { - throw new \RuntimeException('This should not happen.'); - } - - return \strcmp( - $a->key->value, - $b->key->value, - ); - }); - - $node->items = $items; - - return $node; - } - - private function isScopeInTest(Node $node): bool - { - $scope = $node->getAttribute('scope'); - - if (!$scope instanceof Analyser\Scope) { - return false; - } - - if (!$scope->isInClass()) { - return false; - } - - $classReflection = $scope->getClassReflection(); - - if (!$classReflection instanceof Reflection\ClassReflection) { - return false; - } - - if (!$classReflection->isSubclassOf(Framework\TestCase::class)) { - return false; - } - - return true; - } -} diff --git a/test/Unit/Rector/SortAssociativeArrayByKey/SortAssociativeArrayByKeyTest.php b/test/Unit/Rector/SortAssociativeArrayByKey/SortAssociativeArrayByKeyTest.php deleted file mode 100644 index 6e1a0153..00000000 --- a/test/Unit/Rector/SortAssociativeArrayByKey/SortAssociativeArrayByKeyTest.php +++ /dev/null @@ -1,38 +0,0 @@ -doTestFile($filePath); - } - - public static function provideData(): \Iterator - { - return self::yieldFilesFromDirectory(__DIR__ . '/../../../Fixture/Rector/SortAssociativeArrayByKey/'); - } - - public function provideConfigFilePath(): string - { - return __DIR__ . '/config/configured_rule.php'; - } -} diff --git a/test/Unit/Rector/SortAssociativeArrayByKey/config/configured_rule.php b/test/Unit/Rector/SortAssociativeArrayByKey/config/configured_rule.php deleted file mode 100644 index e136006c..00000000 --- a/test/Unit/Rector/SortAssociativeArrayByKey/config/configured_rule.php +++ /dev/null @@ -1,19 +0,0 @@ -rule(PhpCsFixer\Config\Test\Rector\SortAssociativeArrayByKey::class); -};