From cc6fef2492d1ebc87a6b23fc502722e9a5184d8a Mon Sep 17 00:00:00 2001 From: TomasVotruba Date: Wed, 13 May 2020 18:15:35 +0200 Subject: [PATCH 1/2] [ElasticsearchDSL] Deprecate single custom rule, better handled by community --- composer.json | 2 - .../elasticsearch-dsl50.yaml | 3 - docs/rector_rules_overview.md | 35 +------ rules/elastic-search-dsl/config/config.yaml | 9 -- .../MethodCall/MigrateFilterToQueryRector.php | 93 ------------------- .../Fixture/fixture.php.inc | 43 --------- .../MigrateFilterToQueryRectorTest.php | 30 ------ sonar-project.properties | 4 +- 8 files changed, 3 insertions(+), 216 deletions(-) delete mode 100644 rules/elastic-search-dsl/config/config.yaml delete mode 100644 rules/elastic-search-dsl/src/Rector/MethodCall/MigrateFilterToQueryRector.php delete mode 100644 rules/elastic-search-dsl/tests/Rector/MethodCall/MigrateFilterToQueryRector/Fixture/fixture.php.inc delete mode 100644 rules/elastic-search-dsl/tests/Rector/MethodCall/MigrateFilterToQueryRector/MigrateFilterToQueryRectorTest.php diff --git a/composer.json b/composer.json index 0de18d83c9eb..dc1df6843c23 100644 --- a/composer.json +++ b/composer.json @@ -74,7 +74,6 @@ "Rector\\Doctrine\\": "rules/doctrine/src", "Rector\\DynamicTypeAnalysis\\": "packages/dynamic-type-analysis/src", "Rector\\DoctrineAnnotationGenerated\\": "packages/doctrine-annotation-generated/src", - "Rector\\ElasticSearchDSL\\": "rules/elastic-search-dsl/src", "Rector\\FileSystemRector\\": "packages/file-system-rector/src", "Rector\\FrameworkMigration\\": "rules/framework-migration/src", "Rector\\Guzzle\\": "rules/guzzle/src", @@ -150,7 +149,6 @@ "Rector\\DoctrineGedmoToKnplabs\\Tests\\": "rules/doctrine-gedmo-to-knplabs/tests", "Rector\\Doctrine\\Tests\\": "rules/doctrine/tests", "Rector\\DynamicTypeAnalysis\\Tests\\": "packages/dynamic-type-analysis/tests", - "Rector\\ElasticSearchDSL\\Tests\\": "rules/elastic-search-dsl/tests", "Rector\\Guzzle\\Tests\\": "rules/guzzle/tests", "Rector\\JMS\\Tests\\": "rules/jms/tests", "Rector\\Laravel\\Tests\\": "rules/laravel/tests", diff --git a/config/set/elasticsearch-dsl/elasticsearch-dsl50.yaml b/config/set/elasticsearch-dsl/elasticsearch-dsl50.yaml index 8f508ecf89a1..57e60a9afaa8 100644 --- a/config/set/elasticsearch-dsl/elasticsearch-dsl50.yaml +++ b/config/set/elasticsearch-dsl/elasticsearch-dsl50.yaml @@ -1,7 +1,5 @@ # https://github.com/ongr-io/ElasticsearchDSL/blob/5.x/CHANGELOG.md services: - Rector\ElasticSearchDSL\Rector\MethodCall\MigrateFilterToQueryRector: null - Rector\Renaming\Rector\Class_\RenameClassRector: $oldToNewClasses: ONGR\ElasticsearchDSL\Query\BoolQuery: 'ONGR\ElasticsearchDSL\Query\Compound\BoolQuery' @@ -44,4 +42,3 @@ services: ONGR\ElasticsearchDSL\Query\MoreLikeThisQuery: 'ONGR\ElasticsearchDSL\Query\Specialized\MoreLikeThisQuery' ONGR\ElasticsearchDSL\Query\ScriptQuery: 'ONGR\ElasticsearchDSL\Query\Specialized\ScriptQuery' ONGR\ElasticsearchDSL\Query\TemplateQuery: 'ONGR\ElasticsearchDSL\Query\Specialized\TemplateQuery' - diff --git a/docs/rector_rules_overview.md b/docs/rector_rules_overview.md index 832fc39f082a..07246494db65 100644 --- a/docs/rector_rules_overview.md +++ b/docs/rector_rules_overview.md @@ -1,4 +1,4 @@ -# All 483 Rectors Overview +# All 482 Rectors Overview - [Projects](#projects) - [General](#general) @@ -17,7 +17,6 @@ - [DoctrineCodeQuality](#doctrinecodequality) (2) - [DoctrineGedmoToKnplabs](#doctrinegedmotoknplabs) (7) - [DynamicTypeAnalysis](#dynamictypeanalysis) (3) -- [ElasticSearchDSL](#elasticsearchdsl) (1) - [FileSystemRector](#filesystemrector) (1) - [Guzzle](#guzzle) (1) - [JMS](#jms) (2) @@ -3848,38 +3847,6 @@ Clean up probe that records argument types
-## ElasticSearchDSL - -### `MigrateFilterToQueryRector` - -- class: [`Rector\ElasticSearchDSL\Rector\MethodCall\MigrateFilterToQueryRector`](/../master/rules/elastic-search-dsl/src/Rector/MethodCall/MigrateFilterToQueryRector.php) -- [test fixtures](/../master/rules/elastic-search-dsl/tests/Rector/MethodCall/MigrateFilterToQueryRector/Fixture) - -Migrates addFilter to addQuery - -```diff - use ONGR\ElasticsearchDSL\Search; - use ONGR\ElasticsearchDSL\Query\TermsQuery; -+use ONGR\ElasticsearchDSL\Query\Compound\BoolQuery; - - class SomeClass - { - public function run() - { - $search = new Search(); - -- $search->addFilter( -- new TermsQuery('categoryIds', [1, 2]) -+ $search->addQuery( -+ new TermsQuery('categoryIds', [1, 2]), -+ BoolQuery::FILTER - ); - } - } -``` - -
- ## FileSystemRector ### `RemoveProjectFileRector` diff --git a/rules/elastic-search-dsl/config/config.yaml b/rules/elastic-search-dsl/config/config.yaml deleted file mode 100644 index ac753eccf914..000000000000 --- a/rules/elastic-search-dsl/config/config.yaml +++ /dev/null @@ -1,9 +0,0 @@ -services: - _defaults: - public: true - autowire: true - - Rector\ElasticSearchDSL\: - resource: '../src' - exclude: - - '../src/Rector/**/*Rector.php' diff --git a/rules/elastic-search-dsl/src/Rector/MethodCall/MigrateFilterToQueryRector.php b/rules/elastic-search-dsl/src/Rector/MethodCall/MigrateFilterToQueryRector.php deleted file mode 100644 index 692e94e0cb54..000000000000 --- a/rules/elastic-search-dsl/src/Rector/MethodCall/MigrateFilterToQueryRector.php +++ /dev/null @@ -1,93 +0,0 @@ -addFilter( - new TermsQuery('categoryIds', [1, 2]) - ); - } -} -PHP - , - <<<'PHP' -use ONGR\ElasticsearchDSL\Search; -use ONGR\ElasticsearchDSL\Query\TermsQuery; -use ONGR\ElasticsearchDSL\Query\Compound\BoolQuery; - -class SomeClass -{ - public function run() - { - $search = new Search(); - - $search->addQuery( - new TermsQuery('categoryIds', [1, 2]), - BoolQuery::FILTER - ); - } -} -PHP - ), - ]); - } - - /** - * @return string[] - */ - public function getNodeTypes(): array - { - return [MethodCall::class]; - } - - /** - * @param MethodCall $node - */ - public function refactor(Node $node): ?Node - { - if (! $this->isObjectType($node, 'ONGR\ElasticsearchDSL\Search')) { - return null; - } - - if (! $this->isName($node->name, 'addFilter')) { - return null; - } - - $node->name = new Identifier('addQuery'); - - $classConstFetch = $this->createClassConstFetch('ONGR\ElasticsearchDSL\Query\Compound\BoolQuery', 'FILTER'); - - $node->args[1] = new Arg($classConstFetch); - - return $node; - } -} diff --git a/rules/elastic-search-dsl/tests/Rector/MethodCall/MigrateFilterToQueryRector/Fixture/fixture.php.inc b/rules/elastic-search-dsl/tests/Rector/MethodCall/MigrateFilterToQueryRector/Fixture/fixture.php.inc deleted file mode 100644 index 52219a7bbc54..000000000000 --- a/rules/elastic-search-dsl/tests/Rector/MethodCall/MigrateFilterToQueryRector/Fixture/fixture.php.inc +++ /dev/null @@ -1,43 +0,0 @@ -addFilter( - new \ONGR\ElasticsearchDSL\Query\TermsQuery('categoryIds', [1, 2]) - ); - - $search->addQuery( - new \ONGR\ElasticsearchDSL\Query\TermsQuery('categoryIds', [1, 2]), \ONGR\ElasticsearchDSL\Query\Compound\BoolQuery::FILTER - ); - } -} - -?> ------ -addQuery( - new \ONGR\ElasticsearchDSL\Query\TermsQuery('categoryIds', [1, 2]), \ONGR\ElasticsearchDSL\Query\Compound\BoolQuery::FILTER - ); - - $search->addQuery( - new \ONGR\ElasticsearchDSL\Query\TermsQuery('categoryIds', [1, 2]), \ONGR\ElasticsearchDSL\Query\Compound\BoolQuery::FILTER - ); - } -} - -?> diff --git a/rules/elastic-search-dsl/tests/Rector/MethodCall/MigrateFilterToQueryRector/MigrateFilterToQueryRectorTest.php b/rules/elastic-search-dsl/tests/Rector/MethodCall/MigrateFilterToQueryRector/MigrateFilterToQueryRectorTest.php deleted file mode 100644 index a8aa5538d377..000000000000 --- a/rules/elastic-search-dsl/tests/Rector/MethodCall/MigrateFilterToQueryRector/MigrateFilterToQueryRectorTest.php +++ /dev/null @@ -1,30 +0,0 @@ -doTestFile($file); - } - - public function provideData(): Iterator - { - return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture'); - } - - protected function getRectorClass(): string - { - return MigrateFilterToQueryRector::class; - } -} diff --git a/sonar-project.properties b/sonar-project.properties index 1bc9be58d96d..8be83d83db47 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -4,9 +4,9 @@ sonar.projectKey=rectorphp_rector # relative paths to source # wildcards don't work :( -sonar.sources=compiler/src,src,rules/autodiscovery/src,rules/architecture/src,packages/attribute-aware-php-doc/src,packages/better-php-doc-parser/src,rules/cakephp/src,rules/celebrity/src,rules/code-quality/src,rules/coding-style/src,packages/console-differ/src,rules/dead-code/src,rules/doctrine/src,rules/doctrine-code-quality/src,rules/framework-migration/src,packages/file-system-rector/src,rules/elastic-search-dsl/src,rules/guzzle/src,rules/laravel/src,rules/legacy/src,rules/mysql-to-mysqli/src,rules/nette-tester-to-phpunit/src,rules/nette-to-symfony/src,rules/nette/src,packages/node-collector/src,packages/node-type-resolver/src,packages/node-name-resolver/src,rules/phpstan/src,packages/phpstan-static-type-mapper/src,rules/phpunit-symfony/src,rules/phpunit/src,rules/psr4/src,rules/php-spec-to-phpunit/src,rules/php52/src,rules/php53/src,rules/php54/src,rules/php55/src,rules/php56/src,rules/php70/src,rules/php71/src,rules/php72/src,rules/php73/src,rules/php74/src,rules/php80/src,rules/removing-static/src,rules/renaming/src,rules/restoration/src,packages/refactoring/src,rules/solid/src,rules/sensio/src,packages/static-type-mapper/src,rules/symfony-code-quality/src,rules/symfony-phpunit/src,rules/symfony/src,rules/twig/src,rules/type-declaration/src,packages/vendor-locker/src,packages/rector-generator/src,rules/strict-code-quality/src,packages/dynamic-type-analysis/src,rules/php-deglobalize/src,rules/phalcon/src,rules/doctrine-gedmo-to-knplabs/src,packages/polyfill/src +sonar.sources=compiler/src,src,rules/autodiscovery/src,rules/architecture/src,packages/attribute-aware-php-doc/src,packages/better-php-doc-parser/src,rules/cakephp/src,rules/celebrity/src,rules/code-quality/src,rules/coding-style/src,packages/console-differ/src,rules/dead-code/src,rules/doctrine/src,rules/doctrine-code-quality/src,rules/framework-migration/src,packages/file-system-rector/src,rules/guzzle/src,rules/laravel/src,rules/legacy/src,rules/mysql-to-mysqli/src,rules/nette-tester-to-phpunit/src,rules/nette-to-symfony/src,rules/nette/src,packages/node-collector/src,packages/node-type-resolver/src,packages/node-name-resolver/src,rules/phpstan/src,packages/phpstan-static-type-mapper/src,rules/phpunit-symfony/src,rules/phpunit/src,rules/psr4/src,rules/php-spec-to-phpunit/src,rules/php52/src,rules/php53/src,rules/php54/src,rules/php55/src,rules/php56/src,rules/php70/src,rules/php71/src,rules/php72/src,rules/php73/src,rules/php74/src,rules/php80/src,rules/removing-static/src,rules/renaming/src,rules/restoration/src,packages/refactoring/src,rules/solid/src,rules/sensio/src,packages/static-type-mapper/src,rules/symfony-code-quality/src,rules/symfony-phpunit/src,rules/symfony/src,rules/twig/src,rules/type-declaration/src,packages/vendor-locker/src,packages/rector-generator/src,rules/strict-code-quality/src,packages/dynamic-type-analysis/src,rules/php-deglobalize/src,rules/phalcon/src,rules/doctrine-gedmo-to-knplabs/src,packages/polyfill/src -sonar.tests=tests,rules/autodiscovery/tests,rules/architecture/tests,packages/better-php-doc-parser/tests,rules/cakephp/tests,rules/celebrity/tests,rules/code-quality/tests,rules/coding-style/tests,rules/dead-code/tests,rules/doctrine/tests,rules/doctrine-code-quality/tests,rules/elastic-search-dsl/tests,rules/guzzle/tests,rules/laravel/tests,rules/legacy/tests,rules/mysql-to-mysqli/tests,rules/nette-tester-to-phpunit/tests,rules/nette-to-symfony/tests,rules/nette/tests,packages/node-type-resolver/tests,utils/phpstan-extensions/src,rules/phpstan/tests,rules/phpunit-symfony/tests,rules/phpunit/tests,rules/psr4/tests,rules/php-spec-to-phpunit/tests,rules/php52/tests,rules/php53/tests,rules/php54/tests,rules/php55/tests,rules/php56/tests,rules/php70/tests,rules/php71/tests,rules/php72/tests,rules/php73/tests,rules/php74/tests,rules/php80/tests,rules/removing-static/tests,rules/renaming/tests,rules/restoration/tests,rules/solid/tests,rules/sensio/tests,rules/symfony-code-quality/tests,rules/symfony-phpunit/tests,rules/symfony/tests,rules/twig/tests,rules/type-declaration/tests,rules/strict-code-quality/tests,packages/dynamic-type-analysis/tests,rules/php-deglobalize/tests,rules/phalcon/tests,utils/documentation-generator/src,utils/phpstan-attribute-type-syncer/src,utils/phpstan-static-type-mapper-checker/src,rules/doctrine-gedmo-to-knplabs/tests,packages/polyfill/tests +sonar.tests=tests,rules/autodiscovery/tests,rules/architecture/tests,packages/better-php-doc-parser/tests,rules/cakephp/tests,rules/celebrity/tests,rules/code-quality/tests,rules/coding-style/tests,rules/dead-code/tests,rules/doctrine/tests,rules/doctrine-code-quality/tests,rules/guzzle/tests,rules/laravel/tests,rules/legacy/tests,rules/mysql-to-mysqli/tests,rules/nette-tester-to-phpunit/tests,rules/nette-to-symfony/tests,rules/nette/tests,packages/node-type-resolver/tests,utils/phpstan-extensions/src,rules/phpstan/tests,rules/phpunit-symfony/tests,rules/phpunit/tests,rules/psr4/tests,rules/php-spec-to-phpunit/tests,rules/php52/tests,rules/php53/tests,rules/php54/tests,rules/php55/tests,rules/php56/tests,rules/php70/tests,rules/php71/tests,rules/php72/tests,rules/php73/tests,rules/php74/tests,rules/php80/tests,rules/removing-static/tests,rules/renaming/tests,rules/restoration/tests,rules/solid/tests,rules/sensio/tests,rules/symfony-code-quality/tests,rules/symfony-phpunit/tests,rules/symfony/tests,rules/twig/tests,rules/type-declaration/tests,rules/strict-code-quality/tests,packages/dynamic-type-analysis/tests,rules/php-deglobalize/tests,rules/phalcon/tests,utils/documentation-generator/src,utils/phpstan-attribute-type-syncer/src,utils/phpstan-static-type-mapper-checker/src,rules/doctrine-gedmo-to-knplabs/tests,packages/polyfill/tests # see https://docs.sonarqube.org/latest/project-administration/narrowing-the-focus/#NarrowingtheFocus-patterns sonar.exclusions=src/**/*.php.inc,rules/**/*.php.inc,packages/**/*.php.inc,packages/**/Fixture/**/*,rules/**/Fixture/**/*,tests/**/Source/**/* From 92ec8b754cd7927a18b52d64ccf0f6fea6f48d17 Mon Sep 17 00:00:00 2001 From: TomasVotruba Date: Wed, 13 May 2020 18:17:21 +0200 Subject: [PATCH 2/2] README: spaces --- README.md | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index c09866bd1d6c..a92b558af076 100644 --- a/README.md +++ b/README.md @@ -139,6 +139,18 @@ vendor/bin/rector process src ## Features +### Paths + +If you're annoyed by repeating paths in arguments, you can move them to config instead: + +```yaml +# rector.yaml +parameters: + paths: + - 'src' + - 'tests' +``` + ### Extra Autoloading Rector relies on whatever autoload setup the project it is fixing is using by using the Composer autoloader as default. To specify your own autoload file, use `--autoload-file` option: @@ -168,7 +180,7 @@ parameters: - '*/src/*/Tests/*' ``` -You can use a whole ruleset, except one rule: +You can use a whole set, except 1 rule: ```yaml # rector.yaml @@ -177,9 +189,7 @@ parameters: - 'Rector\CodeQuality\Rector\If_\SimplifyIfReturnBoolRector' ``` -### How to Skip Specific Line + Specific Rule? - -Use `@noRector \FQN name` annotation: +For in-file exclusion, use `@noRector \FQN name` annotation: ```php class SomeClass @@ -205,18 +215,6 @@ parameters: php_version_features: '7.2' # your version is 7.3 ``` -### Paths - -If you're annoyed by repeating paths in arguments, you can move them to config instead: - -```yaml -# rector.yaml -parameters: - paths: - - 'src' - - 'tests' -``` - ### Import Use Statements FQN classes are not imported by default. If you don't want to do it manually after every Rector run, enable it by: @@ -261,6 +259,8 @@ parameters: symfony_container_xml_path: 'var/cache/dev/AppKernelDevDebugContainer.xml' ``` +
+ ## More Detailed Documentation - **[All Rectors Overview](/docs/rector_rules_overview.md)** @@ -270,10 +270,14 @@ parameters: - [PHP Parser Nodes Overview](/docs/nodes_overview.md) - [Add Checkstyle with your CI](/docs/checkstyle.md) +
+ ## How to Contribute See [the contribution guide](/CONTRIBUTING.md). +
+ ## Run Rector in Docker You can run Rector on your project using Docker: @@ -293,7 +297,9 @@ docker run -v $(pwd):/project rector/rector:latest process /project/app \ --dry-run ``` -### Community Packages +
+ +## Community Packages Do you use Rector to upgrade your code? Add it here: