From 339cc9f98b84a1db5d39459941e9690f777a3f7a Mon Sep 17 00:00:00 2001 From: naveen <172697+naveensrinivasan@users.noreply.github.com> Date: Sat, 28 May 2022 00:40:07 +0000 Subject: [PATCH 01/37] chore: Set permissions for GitHub actions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Restrict the GitHub token permissions only to the required ones; this way, even if the attackers will succeed in compromising your workflow, they won’t be able to do much. - Included permissions for the action. https://github.com/ossf/scorecard/blob/main/docs/checks.md#token-permissions https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#permissions https://docs.github.com/en/actions/using-jobs/assigning-permissions-to-jobs [Keeping your GitHub Actions and workflows secure Part 1: Preventing pwn requests](https://securitylab.github.com/research/github-actions-preventing-pwn-requests/) Signed-off-by: naveen <172697+naveensrinivasan@users.noreply.github.com> --- .github/workflows/grumphp.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/grumphp.yml b/.github/workflows/grumphp.yml index 0a502113..e26493b3 100644 --- a/.github/workflows/grumphp.yml +++ b/.github/workflows/grumphp.yml @@ -1,6 +1,9 @@ name: GrumPHP on: [push, pull_request] +permissions: + contents: read + jobs: run: runs-on: ${{ matrix.operating-system }} From 7bc55d40f32b83dc2e6dec923ece994fc6c23fb7 Mon Sep 17 00:00:00 2001 From: naveen <172697+naveensrinivasan@users.noreply.github.com> Date: Sun, 29 May 2022 01:29:27 +0000 Subject: [PATCH 02/37] chore: Included githubactions in the dependabot config This should help with keeping the GitHub actions updated on new releases. This will also help with keeping it secure. Dependabot helps in keeping the supply chain secure https://docs.github.com/en/code-security/dependabot GitHub actions up to date https://docs.github.com/en/code-security/dependabot/working-with-dependabot/keeping-your-actions-up-to-date-with-dependabot https://github.com/ossf/scorecard/blob/main/docs/checks.md#dependency-update-tool Signed-off-by: naveen <172697+naveensrinivasan@users.noreply.github.com> --- .github/dependabot.yml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .github/dependabot.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 00000000..203f3c88 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,6 @@ +version: 2 +updates: +- package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "weekly" From 2279f94b372255e5db91f4e812ed3984665a8ab3 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 29 May 2022 06:56:32 +0000 Subject: [PATCH 03/37] Bump actions/cache from 2 to 3 Bumps [actions/cache](https://github.com/actions/cache) from 2 to 3. - [Release notes](https://github.com/actions/cache/releases) - [Changelog](https://github.com/actions/cache/blob/main/RELEASES.md) - [Commits](https://github.com/actions/cache/compare/v2...v3) --- updated-dependencies: - dependency-name: actions/cache dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/grumphp.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/grumphp.yml b/.github/workflows/grumphp.yml index e26493b3..5c6ee6b3 100644 --- a/.github/workflows/grumphp.yml +++ b/.github/workflows/grumphp.yml @@ -33,7 +33,7 @@ jobs: id: composercache run: echo "::set-output name=dir::$(composer config cache-files-dir)" - name: Cache dependencies - uses: actions/cache@v2 + uses: actions/cache@v3 with: path: ${{ steps.composercache.outputs.dir }} key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} From d133b4bebf81221efa94b86628c93393ae20881a Mon Sep 17 00:00:00 2001 From: naveen <172697+naveensrinivasan@users.noreply.github.com> Date: Mon, 30 May 2022 17:45:19 +0000 Subject: [PATCH 04/37] chore(deps): Included dependency review > Dependency Review GitHub Action in your repository to enforce dependency > reviews on your pull requests. > The action scans for vulnerable versions of dependencies introduced by package version > changes in pull requests, > and warns you about the associated security vulnerabilities. > This gives you better visibility of what's changing in a pull request, > and helps prevent vulnerabilities being added to your repository. https://docs.github.com/en/code-security/supply-chain-security/understanding-your-software-supply-chain/about-dependency-review#dependency-review-enforcement Signed-off-by: naveen <172697+naveensrinivasan@users.noreply.github.com> --- .github/workflows/depsreview.yaml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 .github/workflows/depsreview.yaml diff --git a/.github/workflows/depsreview.yaml b/.github/workflows/depsreview.yaml new file mode 100644 index 00000000..f2605b7a --- /dev/null +++ b/.github/workflows/depsreview.yaml @@ -0,0 +1,14 @@ +name: 'Dependency Review' +on: [pull_request] + +permissions: + contents: read + +jobs: + dependency-review: + runs-on: ubuntu-latest + steps: + - name: 'Checkout Repository' + uses: actions/checkout@v3 + - name: 'Dependency Review' + uses: actions/dependency-review-action@v1 From d4a890f0081ee0cde917a7458d081b2d11db11f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikola=20Mijajlovi=C4=87?= Date: Wed, 1 Jun 2022 21:16:21 +0200 Subject: [PATCH 05/37] Support Monolog 3 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 68e3d6a3..44da6a20 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,7 @@ "doctrine/collections": "^1.6.8", "gitonomy/gitlib": "^1.3", "laravel/serializable-closure": "^1.1", - "monolog/monolog": "^2.0", + "monolog/monolog": "^2.0 || ^3.0", "ondram/ci-detector": "^4.0", "psr/container": "^1.1 || ^2.0", "seld/jsonlint": "~1.8", From 8914dc4d05c60d467f9e0916eb2855a7f8fb180d Mon Sep 17 00:00:00 2001 From: Wanne Van Camp <3399877+wannevancamp@users.noreply.github.com> Date: Sun, 19 Jun 2022 10:08:23 +0200 Subject: [PATCH 06/37] Update securitychecker.md `securitychecker_roave` was missing in the `Security Checker` list --- doc/tasks/securitychecker.md | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/tasks/securitychecker.md b/doc/tasks/securitychecker.md index 0d49eeed..b6458094 100644 --- a/doc/tasks/securitychecker.md +++ b/doc/tasks/securitychecker.md @@ -6,4 +6,5 @@ You can use one of following tasks as a replacement: - [securitychecker_enlightn](securitychecker/enlightn.md) - [securitychecker_local](securitychecker/local.md) +- [securitychecker_roave](securitychecker/roave.md) - [securitychecker_symfony](securitychecker/symfony.md) From 3fa96336cf87e2b78fd713277129bfd378cec720 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 20 Jun 2022 23:33:05 +0000 Subject: [PATCH 07/37] Bump actions/dependency-review-action from 1 to 2 Bumps [actions/dependency-review-action](https://github.com/actions/dependency-review-action) from 1 to 2. - [Release notes](https://github.com/actions/dependency-review-action/releases) - [Commits](https://github.com/actions/dependency-review-action/compare/v1...v2) --- updated-dependencies: - dependency-name: actions/dependency-review-action dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/depsreview.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/depsreview.yaml b/.github/workflows/depsreview.yaml index f2605b7a..a25de591 100644 --- a/.github/workflows/depsreview.yaml +++ b/.github/workflows/depsreview.yaml @@ -11,4 +11,4 @@ jobs: - name: 'Checkout Repository' uses: actions/checkout@v3 - name: 'Dependency Review' - uses: actions/dependency-review-action@v1 + uses: actions/dependency-review-action@v2 From 3ec61c1678c4c370f02b05fef606fd561d923c8e Mon Sep 17 00:00:00 2001 From: Toon Verwerft Date: Fri, 24 Jun 2022 10:32:25 +0200 Subject: [PATCH 08/37] 1.13.0 release --- src/Console/ApplicationConfigurator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Console/ApplicationConfigurator.php b/src/Console/ApplicationConfigurator.php index c129bbbf..42aeaa60 100644 --- a/src/Console/ApplicationConfigurator.php +++ b/src/Console/ApplicationConfigurator.php @@ -10,7 +10,7 @@ class ApplicationConfigurator { const APP_NAME = 'GrumPHP'; - const APP_VERSION = '1.12.0'; + const APP_VERSION = '1.13.0'; public function configure(Application $application): void { From 23c93a1140d6620f2318221811805463e3c4364c Mon Sep 17 00:00:00 2001 From: Travis Carden Date: Wed, 6 Jul 2022 12:33:39 -0400 Subject: [PATCH 09/37] Add 'cache_file' parameter to 'deptrac' task. --- doc/tasks/deptrac.md | 7 +++++++ src/Task/Deptrac.php | 3 +++ test/Unit/Task/DeptracTest.php | 1 + 3 files changed, 11 insertions(+) diff --git a/doc/tasks/deptrac.md b/doc/tasks/deptrac.md index 7a886a62..968412f9 100644 --- a/doc/tasks/deptrac.md +++ b/doc/tasks/deptrac.md @@ -12,11 +12,18 @@ namespace and has following configurable parameters: grumphp: tasks: deptrac: + cache_file: ~ depfile: ~ formatter: ~ output: ~ ``` +**cache_file** + +*Default: null* + +Set location where cache file will be stored. Example: `/var/www/src/.deptrac.cache` + **depfile** *Default: null* diff --git a/src/Task/Deptrac.php b/src/Task/Deptrac.php index 5c18a29d..a58bbb57 100644 --- a/src/Task/Deptrac.php +++ b/src/Task/Deptrac.php @@ -20,11 +20,13 @@ public static function getConfigurableOptions(): OptionsResolver { $resolver = new OptionsResolver(); $resolver->setDefaults([ + 'cache_file' => null, 'depfile' => null, 'formatter' => null, 'output' => null, ]); + $resolver->addAllowedTypes('cache_file', ['null', 'string']); $resolver->addAllowedTypes('depfile', ['null', 'string']); $resolver->addAllowedTypes('formatter', ['null', 'string']); $resolver->addAllowedTypes('output', ['null', 'string']); @@ -50,6 +52,7 @@ public function run(ContextInterface $context): TaskResultInterface $arguments->add('analyse'); $arguments->addOptionalArgument('--formatter=%s', $config['formatter']); $arguments->addOptionalArgument('--output=%s', $config['output']); + $arguments->addOptionalArgument('--cache-file=%s', $config['cache_file']); $arguments->addOptionalArgument('--config-file=%s', $config['depfile']); $process = $this->processBuilder->buildProcess($arguments); diff --git a/test/Unit/Task/DeptracTest.php b/test/Unit/Task/DeptracTest.php index 2420e6bc..83a3f6ab 100644 --- a/test/Unit/Task/DeptracTest.php +++ b/test/Unit/Task/DeptracTest.php @@ -25,6 +25,7 @@ public function provideConfigurableOptions(): iterable yield 'defaults' => [ [], [ + 'cache_file' => null, 'depfile' => null, 'formatter' => null, 'output' => null, From eedbe734b5021468d1484ec8e06e921ddffc5106 Mon Sep 17 00:00:00 2001 From: Travis Carden Date: Thu, 11 Aug 2022 16:38:19 -0400 Subject: [PATCH 10/37] Add test value set. --- test/Unit/Task/DeptracTest.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/test/Unit/Task/DeptracTest.php b/test/Unit/Task/DeptracTest.php index 83a3f6ab..d17d9c62 100644 --- a/test/Unit/Task/DeptracTest.php +++ b/test/Unit/Task/DeptracTest.php @@ -99,6 +99,17 @@ public function provideExternalTaskRuns(): iterable 'analyse', ] ]; + yield 'cache-file' => [ + [ + 'cache_file' => 'example.cache', + ], + $this->mockContext(RunContext::class, ['hello.php', 'hello2.php']), + 'deptrac', + [ + 'analyse', + '--cache-file=example.cache', + ] + ]; yield 'formatter-graphviz' => [ [ 'formatter' => 'graphviz-display', From 1e8c9fe55bcf3dc31e71f00d3f527a563e67e8de Mon Sep 17 00:00:00 2001 From: Toon Verwerft Date: Fri, 26 Aug 2022 08:16:45 +0200 Subject: [PATCH 11/37] Make it possible to null out ascii config --- src/Configuration/Configuration.php | 5 +- test/Unit/Configuration/ConfigurationTest.php | 76 +++++++++++++++++++ 2 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 test/Unit/Configuration/ConfigurationTest.php diff --git a/src/Configuration/Configuration.php b/src/Configuration/Configuration.php index c1708445..2f96fdaa 100644 --- a/src/Configuration/Configuration.php +++ b/src/Configuration/Configuration.php @@ -63,7 +63,10 @@ public function getConfigTreeBuilder(): TreeBuilder $rootNode->children()->arrayNode('extensions')->scalarPrototype(); // ascii - $ascii = $rootNode->children()->arrayNode('ascii')->addDefaultsIfNotSet(); + $ascii = $rootNode->children()->arrayNode('ascii')->addDefaultsIfNotSet()->treatNullLike([ + 'failed' => null, + 'succeeded' => null, + ]); $ascii->children()->variableNode('failed')->defaultValue('grumphp-grumpy.txt'); $ascii->children()->variableNode('succeeded')->defaultValue('grumphp-happy.txt'); diff --git a/test/Unit/Configuration/ConfigurationTest.php b/test/Unit/Configuration/ConfigurationTest.php new file mode 100644 index 00000000..bb3934cd --- /dev/null +++ b/test/Unit/Configuration/ConfigurationTest.php @@ -0,0 +1,76 @@ +parse($config); + + self::assertArrayContains($expected, $actual); + } + + public function provideConfigs() + { + yield 'ascii_not_set' => [ + [], + ['ascii' => [ + 'failed' => 'grumphp-grumpy.txt', + 'succeeded' => 'grumphp-happy.txt', + ]] + ]; + yield 'ascii_nulled_out_items' => [ + ['ascii' => [ + 'failed' => null, + 'succeeded' => null, + ]], + ['ascii' => [ + 'failed' => null, + 'succeeded' => null, + ]] + ]; + yield 'ascii_custom' => [ + ['ascii' => [ + 'failed' => 'custom-failure.txt', + 'succeeded' => 'custom-happy.txt', + ]], + ['ascii' => [ + 'failed' => 'custom-failure.txt', + 'succeeded' => 'custom-happy.txt', + ]] + ]; + yield 'ascii_nulled_out' => [ + ['ascii' => null], + ['ascii' => [ + 'failed' => null, + 'succeeded' => null, + ]] + ]; + } + + private function parse(array $config): array + { + $configuration = new Configuration(); + $processor = new Processor(); + + return $processor->process($configuration->getConfigTreeBuilder()->buildTree(), ['grumphp' => $config]); + } + + private function assertArrayContains(array $needle, array $haystack) + { + self::assertSame( + array_intersect_key($haystack, $needle), + $needle + ); + } +} From a14949fc8853d0d63c74a72f48c2474de774f7c8 Mon Sep 17 00:00:00 2001 From: Jeroen Tubex Date: Fri, 26 Aug 2022 08:41:52 +0200 Subject: [PATCH 12/37] Add docs --- doc/tasks/phparkitect.md | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 doc/tasks/phparkitect.md diff --git a/doc/tasks/phparkitect.md b/doc/tasks/phparkitect.md new file mode 100644 index 00000000..e1318671 --- /dev/null +++ b/doc/tasks/phparkitect.md @@ -0,0 +1,40 @@ +# PHPArkitect + +PHPArkitect helps you to keep your PHP codebase coherent and solid, by permitting to add some architectural constraint check to your workflow. +It lives under the `phparkitect` namespace and has following configurable parameters: + +## Composer +```bash +composer require --dev phparkitect/phparkitect +``` + +## Config +```yaml +# grumphp.yml +grumphp: + tasks: + phparkitect: + configuration: ~ + target_php_version: ~ + stop_on_failure: ~ +``` + +**configuration** + +*Default: null* + +With this parameter you can specify the path your project's configuration file. +By defaykt PHPArkitect will search all rules in phparkitect.php located in the root of your project. + +**target_php_version** + +*Default: null* + +With this parameter, you can specify which PHP version should use the parser. +This can be useful to debug problems and to understand if there are problems with a different PHP version. + +**stop_on_failure** + +*Default: null* + +With this option the process will end immediately after the first violation. From 312e0257dc15d5836f2a932fcdd12550d5923352 Mon Sep 17 00:00:00 2001 From: Jeroen Tubex Date: Fri, 26 Aug 2022 09:24:58 +0200 Subject: [PATCH 13/37] Add phparkitect task and test --- composer.json | 1 + doc/tasks/phparkitect.md | 9 +- src/Task/PhpArkitect.php | 67 ++++++++++++++ test/Unit/Task/PhpArkitectTest.php | 135 +++++++++++++++++++++++++++++ 4 files changed, 209 insertions(+), 3 deletions(-) create mode 100644 src/Task/PhpArkitect.php create mode 100644 test/Unit/Task/PhpArkitectTest.php diff --git a/composer.json b/composer.json index 44da6a20..5ca87327 100644 --- a/composer.json +++ b/composer.json @@ -69,6 +69,7 @@ "phan/phan": "Lets GrumPHP unleash a static analyzer on your code", "phing/phing": "Lets GrumPHP run your automated PHP tasks.", "php-parallel-lint/php-parallel-lint": "Lets GrumPHP quickly lint your entire code base.", + "phparkitect/phparkitect": "Let GrumPHP keep your codebase coherent and solid, by permitting to add some architectural constraint check to your workflow.", "phpmd/phpmd": "Lets GrumPHP sort out the mess in your code", "phpspec/phpspec": "Lets GrumPHP spec your code.", "phpstan/phpstan": "Lets GrumPHP discover bugs in your code without running it.", diff --git a/doc/tasks/phparkitect.md b/doc/tasks/phparkitect.md index e1318671..a055b586 100644 --- a/doc/tasks/phparkitect.md +++ b/doc/tasks/phparkitect.md @@ -3,6 +3,9 @@ PHPArkitect helps you to keep your PHP codebase coherent and solid, by permitting to add some architectural constraint check to your workflow. It lives under the `phparkitect` namespace and has following configurable parameters: +PhpArkitect doesn't support specifying the directory or files. +It will always run on the directories specified in your config file. + ## Composer ```bash composer require --dev phparkitect/phparkitect @@ -14,17 +17,17 @@ composer require --dev phparkitect/phparkitect grumphp: tasks: phparkitect: - configuration: ~ + config: ~ target_php_version: ~ stop_on_failure: ~ ``` -**configuration** +**config** *Default: null* With this parameter you can specify the path your project's configuration file. -By defaykt PHPArkitect will search all rules in phparkitect.php located in the root of your project. +By default PHPArkitect will search all rules in phparkitect.php located in the root of your project. **target_php_version** diff --git a/src/Task/PhpArkitect.php b/src/Task/PhpArkitect.php new file mode 100644 index 00000000..1b51b408 --- /dev/null +++ b/src/Task/PhpArkitect.php @@ -0,0 +1,67 @@ +setDefaults([ + 'config' => null, + "target_php_version" => null, + 'stop_on_failure' => null, + ]); + + $resolver->addAllowedTypes('config', ['null', 'string']); + $resolver->addAllowedTypes('target_php_version', ['null', 'string']); + $resolver->addAllowedTypes('stop_on_failure', ['null', 'boolean']); + + return $resolver; + } + + /** + * {@inheritdoc} + */ + public function canRunInContext(ContextInterface $context): bool + { + return $context instanceof GitPreCommitContext || $context instanceof RunContext; + } + + /** + * {@inheritdoc} + */ + public function run(ContextInterface $context): TaskResultInterface + { + $config = $this->getConfig()->getOptions(); + + $arguments = $this->processBuilder->createArgumentsForCommand('phparkitect'); + $arguments->add('check'); + $arguments->addOptionalArgument('--config=%s', $config['config']); + $arguments->addOptionalArgument('--target-php-version=%s', $config['target_php_version']); + $arguments->addOptionalArgument('--stop-on-failure', $config['stop_on_failure']); + $arguments->add('--no-ansi'); + $arguments->add('--no-interaction'); + + $process = $this->processBuilder->buildProcess($arguments); + $process->run(); + + if (!$process->isSuccessful()) { + return TaskResult::createFailed($this, $context, $this->formatter->format($process)); + } + + return TaskResult::createPassed($this, $context); + } +} diff --git a/test/Unit/Task/PhpArkitectTest.php b/test/Unit/Task/PhpArkitectTest.php new file mode 100644 index 00000000..2249d1ec --- /dev/null +++ b/test/Unit/Task/PhpArkitectTest.php @@ -0,0 +1,135 @@ +processBuilder->reveal(), + $this->formatter->reveal() + ); + } + + public function provideConfigurableOptions(): iterable + { + yield 'defaults' => [ + [], + [ + 'config' => null, + 'target_php_version' => null, + 'stop_on_failure' => null, + ], + ]; + } + + public function provideRunContexts(): iterable + { + yield 'run-context' => [ + true, + $this->mockContext(RunContext::class) + ]; + + yield 'pre-commit-context' => [ + true, + $this->mockContext(GitPreCommitContext::class) + ]; + + yield 'other' => [ + false, + $this->mockContext() + ]; + } + + public function provideFailsOnStuff(): iterable + { + yield 'exitCode1' => [ + [], + $this->mockContext(RunContext::class, ['hello.php']), + function () { + $this->mockProcessBuilder('phparkitect', $process = $this->mockProcess(1)); + $this->formatter->format($process)->willReturn('nope'); + }, + 'nope' + ]; + } + + public function providePassesOnStuff(): iterable + { + yield 'exitCode0' => [ + [], + $this->mockContext(RunContext::class, ['hello.php']), + function () { + $this->mockProcessBuilder('phparkitect', $this->mockProcess(0)); + } + ]; + } + + public function provideSkipsOnStuff(): iterable + { + return []; + } + + public function provideExternalTaskRuns(): iterable + { + yield 'defaults' => [ + [], + $this->mockContext(RunContext::class, ['hello.php', 'hello2.php']), + 'phparkitect', + [ + 'check', + '--no-ansi', + '--no-interaction' + ] + ]; + yield 'config' => [ + [ + 'config' => 'phparkitect.php' + ], + $this->mockContext(RunContext::class, ['hello.php', 'hello2.php']), + 'phparkitect', + [ + 'check', + '--config=phparkitect.php', + '--no-ansi', + '--no-interaction' + ] + ]; + yield 'target_php_version' => [ + [ + 'target_php_version' => '8.1' + ], + $this->mockContext(RunContext::class, ['hello.php', 'hello2.php']), + 'phparkitect', + [ + 'check', + '--target-php-version=8.1', + '--no-ansi', + '--no-interaction' + ] + ]; + yield 'stop_on_failure' => [ + [ + 'stop_on_failure' => TRUE + ], + $this->mockContext(RunContext::class, ['hello.php', 'hello2.php']), + 'phparkitect', + [ + 'check', + '--stop-on-failure', + '--no-ansi', + '--no-interaction' + ] + ]; + } +} From 262bc8e36f3b9c5cb2e774c191a39e85ddd00171 Mon Sep 17 00:00:00 2001 From: Jeroen Tubex Date: Fri, 26 Aug 2022 09:30:33 +0200 Subject: [PATCH 14/37] Add task to docs and tasks.yml --- doc/tasks.md | 1 + resources/config/tasks.yml | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/doc/tasks.md b/doc/tasks.md index df569e96..6d69d750 100644 --- a/doc/tasks.md +++ b/doc/tasks.md @@ -100,6 +100,7 @@ Every task has its own default configuration. It is possible to overwrite the pa - [Phan](tasks/phan.md) - [Phing](tasks/phing.md) - [Php7cc](tasks/php7cc.md) +- [PhpArkitect](tasks/phparkitect.md) - [PhpCpd](tasks/phpcpd.md) - [Phpcs](tasks/phpcs.md) - [PHP-CS-Fixer](tasks/phpcsfixer.md) diff --git a/resources/config/tasks.yml b/resources/config/tasks.yml index 654daa24..8f11d851 100644 --- a/resources/config/tasks.yml +++ b/resources/config/tasks.yml @@ -211,6 +211,13 @@ services: tags: - {name: grumphp.task, task: php7cc} + GrumPHP\Task\PhpArkitect: + arguments: + - '@process_builder' + - '@formatter.raw_process' + tags: + - {name: grumphp.task, task: phparkitect} + GrumPHP\Task\PhpCpd: arguments: - '@process_builder' From c36da7715c7a3cc6572860c556198daf9a8347b0 Mon Sep 17 00:00:00 2001 From: Jeroen Tubex Date: Fri, 26 Aug 2022 09:36:17 +0200 Subject: [PATCH 15/37] Update docs --- doc/tasks/phparkitect.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/tasks/phparkitect.md b/doc/tasks/phparkitect.md index a055b586..f969f8a0 100644 --- a/doc/tasks/phparkitect.md +++ b/doc/tasks/phparkitect.md @@ -3,8 +3,8 @@ PHPArkitect helps you to keep your PHP codebase coherent and solid, by permitting to add some architectural constraint check to your workflow. It lives under the `phparkitect` namespace and has following configurable parameters: -PhpArkitect doesn't support specifying the directory or files. -It will always run on the directories specified in your config file. +PhpArkitect doesn't support checking only the changed files. +It will always run on the directory specified in your config file. ## Composer ```bash From 2f7fc54db35ac6c05a92db4bef9cb584a165f958 Mon Sep 17 00:00:00 2001 From: Jeroen Tubex Date: Fri, 26 Aug 2022 10:53:52 +0200 Subject: [PATCH 16/37] Fix feedback --- src/Task/PhpArkitect.php | 5 ++--- test/Unit/Task/PhpArkitectTest.php | 1 - 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Task/PhpArkitect.php b/src/Task/PhpArkitect.php index 1b51b408..ae5df016 100644 --- a/src/Task/PhpArkitect.php +++ b/src/Task/PhpArkitect.php @@ -22,12 +22,12 @@ public static function getConfigurableOptions(): OptionsResolver $resolver->setDefaults([ 'config' => null, "target_php_version" => null, - 'stop_on_failure' => null, + 'stop_on_failure' => false, ]); $resolver->addAllowedTypes('config', ['null', 'string']); $resolver->addAllowedTypes('target_php_version', ['null', 'string']); - $resolver->addAllowedTypes('stop_on_failure', ['null', 'boolean']); + $resolver->addAllowedTypes('stop_on_failure', ['boolean']); return $resolver; } @@ -52,7 +52,6 @@ public function run(ContextInterface $context): TaskResultInterface $arguments->addOptionalArgument('--config=%s', $config['config']); $arguments->addOptionalArgument('--target-php-version=%s', $config['target_php_version']); $arguments->addOptionalArgument('--stop-on-failure', $config['stop_on_failure']); - $arguments->add('--no-ansi'); $arguments->add('--no-interaction'); $process = $this->processBuilder->buildProcess($arguments); diff --git a/test/Unit/Task/PhpArkitectTest.php b/test/Unit/Task/PhpArkitectTest.php index 2249d1ec..399eb778 100644 --- a/test/Unit/Task/PhpArkitectTest.php +++ b/test/Unit/Task/PhpArkitectTest.php @@ -7,7 +7,6 @@ use GrumPHP\Task\Context\GitPreCommitContext; use GrumPHP\Task\Context\RunContext; use GrumPHP\Task\PhpArkitect; -use GrumPHP\Task\PhpStan; use GrumPHP\Task\TaskInterface; use GrumPHP\Test\Task\AbstractExternalTaskTestCase; From 791de4786a5693b6c87b396061dd48234de4af73 Mon Sep 17 00:00:00 2001 From: Jeroen Tubex Date: Fri, 26 Aug 2022 10:55:08 +0200 Subject: [PATCH 17/37] Fix failing tests --- test/Unit/Task/PhpArkitectTest.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/test/Unit/Task/PhpArkitectTest.php b/test/Unit/Task/PhpArkitectTest.php index 399eb778..93df2002 100644 --- a/test/Unit/Task/PhpArkitectTest.php +++ b/test/Unit/Task/PhpArkitectTest.php @@ -27,7 +27,7 @@ public function provideConfigurableOptions(): iterable [ 'config' => null, 'target_php_version' => null, - 'stop_on_failure' => null, + 'stop_on_failure' => false, ], ]; } @@ -87,7 +87,6 @@ public function provideExternalTaskRuns(): iterable 'phparkitect', [ 'check', - '--no-ansi', '--no-interaction' ] ]; @@ -100,7 +99,6 @@ public function provideExternalTaskRuns(): iterable [ 'check', '--config=phparkitect.php', - '--no-ansi', '--no-interaction' ] ]; @@ -113,7 +111,6 @@ public function provideExternalTaskRuns(): iterable [ 'check', '--target-php-version=8.1', - '--no-ansi', '--no-interaction' ] ]; @@ -126,7 +123,6 @@ public function provideExternalTaskRuns(): iterable [ 'check', '--stop-on-failure', - '--no-ansi', '--no-interaction' ] ]; From d60124b1f8fdbd711280cdfdf50a15f6e5589a9f Mon Sep 17 00:00:00 2001 From: Jeroen Tubex Date: Fri, 26 Aug 2022 11:28:06 +0200 Subject: [PATCH 18/37] Update phpArkitect default value for stop_on_failure to false --- doc/tasks/phparkitect.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/tasks/phparkitect.md b/doc/tasks/phparkitect.md index f969f8a0..4689cad2 100644 --- a/doc/tasks/phparkitect.md +++ b/doc/tasks/phparkitect.md @@ -38,6 +38,6 @@ This can be useful to debug problems and to understand if there are problems wit **stop_on_failure** -*Default: null* +*Default: false* With this option the process will end immediately after the first violation. From 7dd96564a38bd3de400347e09a219e38c43517a0 Mon Sep 17 00:00:00 2001 From: Dennis de Best Date: Wed, 28 Sep 2022 13:43:19 +0200 Subject: [PATCH 19/37] Update ParaTest documentation The option "debugger" does not exist. --- doc/tasks/paratest.md | 1 - 1 file changed, 1 deletion(-) diff --git a/doc/tasks/paratest.md b/doc/tasks/paratest.md index bb4ecf90..d722bc7f 100644 --- a/doc/tasks/paratest.md +++ b/doc/tasks/paratest.md @@ -24,7 +24,6 @@ grumphp: phpunit: null configuration: null runner: null - debugger: null coverage-clover: null coverage-html: null coverage-php: null From 53ca260aa7c5561f52854acaa7ff2363943badfe Mon Sep 17 00:00:00 2001 From: Dominik Ziegler Date: Thu, 6 Oct 2022 16:49:07 +0200 Subject: [PATCH 20/37] Include filename in AbstractVisitor error messages --- src/Parser/Php/Visitor/AbstractVisitor.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Parser/Php/Visitor/AbstractVisitor.php b/src/Parser/Php/Visitor/AbstractVisitor.php index 186295b3..4627477d 100644 --- a/src/Parser/Php/Visitor/AbstractVisitor.php +++ b/src/Parser/Php/Visitor/AbstractVisitor.php @@ -27,7 +27,7 @@ public function setContext(ParserContext $context): void protected function addError(string $message, int $line = -1, string $type = ParseError::TYPE_ERROR): void { $errors = $this->context->getErrors(); - $fileName = $this->context->getFile()->getPath(); + $fileName = $this->context->getFile()->getPathname(); $errors->add(new PhpParserError($type, $message, $fileName, $line)); } } From 61061d9eb22a6b5a7653f4a7af5a2934b9c766ea Mon Sep 17 00:00:00 2001 From: Ulrik nielsen Date: Thu, 6 Oct 2022 16:58:59 +0200 Subject: [PATCH 21/37] Added deprecation to whitelist_patterns with null value Added new test Changed default value of whitelist_patterns to an empty array, as per the documentation. Fixed default value in test set --- src/Task/ESLint.php | 14 +++++++++++--- test/Unit/Task/ESLintTest.php | 9 ++++++++- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/Task/ESLint.php b/src/Task/ESLint.php index df136178..72e7345d 100644 --- a/src/Task/ESLint.php +++ b/src/Task/ESLint.php @@ -23,8 +23,8 @@ public static function getConfigurableOptions(): OptionsResolver // Task config options 'bin' => null, 'triggered_by' => ['js', 'jsx', 'ts', 'tsx', 'vue'], - 'whitelist_patterns' => null, - + 'whitelist_patterns' => [], + // ESLint native config options 'config' => null, 'ignore_path' => null, @@ -39,7 +39,7 @@ public static function getConfigurableOptions(): OptionsResolver $resolver->addAllowedTypes('bin', ['null', 'string']); $resolver->addAllowedTypes('whitelist_patterns', ['null', 'array']); $resolver->addAllowedTypes('triggered_by', ['array']); - + // ESLint native config options $resolver->addAllowedTypes('config', ['null', 'string']); $resolver->addAllowedTypes('ignore_path', ['null', 'string']); @@ -49,6 +49,14 @@ public static function getConfigurableOptions(): OptionsResolver $resolver->addAllowedTypes('no_eslintrc', ['bool']); $resolver->addAllowedTypes('quiet', ['bool']); + $resolver->setDeprecated('whitelist_patterns', 'phpro/grumphp', '1.13', function (Options $options, $value): string { + if (null === $value) { + return 'Parsing "null" to option "whitelist_patterns" is deprecated, pass an array instead.'; + } + + return ''; + }); + return $resolver; } diff --git a/test/Unit/Task/ESLintTest.php b/test/Unit/Task/ESLintTest.php index 43531ed8..d2dc775d 100644 --- a/test/Unit/Task/ESLintTest.php +++ b/test/Unit/Task/ESLintTest.php @@ -29,7 +29,7 @@ public function provideConfigurableOptions(): iterable // Task config options 'bin' => null, 'triggered_by' => ['js', 'jsx', 'ts', 'tsx', 'vue'], - 'whitelist_patterns' => null, + 'whitelist_patterns' => [], // ESLint native config options 'config' => null, @@ -207,4 +207,11 @@ public function provideExternalTaskRuns(): iterable ] ]; } + + /** + * @test + */ + public function it_triggers_deprecation_on_null() { + self::assertTrue(ESLint::getConfigurableOptions()->isDeprecated('whitelist_patterns')); + } } From 8a476e80846243378bd049962e1dbc1a67a2ab4a Mon Sep 17 00:00:00 2001 From: Ulrik nielsen Date: Thu, 6 Oct 2022 17:55:28 +0200 Subject: [PATCH 22/37] Fixed missing use statement --- src/Task/ESLint.php | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/Task/ESLint.php b/src/Task/ESLint.php index 72e7345d..46a513b6 100644 --- a/src/Task/ESLint.php +++ b/src/Task/ESLint.php @@ -11,6 +11,7 @@ use GrumPHP\Task\Context\ContextInterface; use GrumPHP\Task\Context\GitPreCommitContext; use GrumPHP\Task\Context\RunContext; +use Symfony\Component\OptionsResolver\Options; use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\Process\Process; @@ -49,13 +50,18 @@ public static function getConfigurableOptions(): OptionsResolver $resolver->addAllowedTypes('no_eslintrc', ['bool']); $resolver->addAllowedTypes('quiet', ['bool']); - $resolver->setDeprecated('whitelist_patterns', 'phpro/grumphp', '1.13', function (Options $options, $value): string { - if (null === $value) { - return 'Parsing "null" to option "whitelist_patterns" is deprecated, pass an array instead.'; - } + $resolver->setDeprecated( + 'whitelist_patterns', + 'phpro/grumphp', + '1.13', + function (Options $options, $value): string { + if (null === $value) { + return 'Parsing "null" to option "whitelist_patterns" is deprecated, pass an array instead.'; + } - return ''; - }); + return ''; + } + ); return $resolver; } From 1d04f794276e94c7af857f32f611c57908ffb99b Mon Sep 17 00:00:00 2001 From: Ulrik nielsen Date: Thu, 6 Oct 2022 18:45:56 +0200 Subject: [PATCH 23/37] Fixed version number in deprecation --- src/Task/ESLint.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Task/ESLint.php b/src/Task/ESLint.php index 46a513b6..0a37c12c 100644 --- a/src/Task/ESLint.php +++ b/src/Task/ESLint.php @@ -53,7 +53,7 @@ public static function getConfigurableOptions(): OptionsResolver $resolver->setDeprecated( 'whitelist_patterns', 'phpro/grumphp', - '1.13', + '1.14', function (Options $options, $value): string { if (null === $value) { return 'Parsing "null" to option "whitelist_patterns" is deprecated, pass an array instead.'; From 8cf3d5c5708e99b26c7af4904a0001c16187ae8f Mon Sep 17 00:00:00 2001 From: Toon Verwerft Date: Fri, 25 Nov 2022 09:07:23 +0100 Subject: [PATCH 24/37] Bump PHP --- .github/workflows/depsreview.yaml | 2 +- .github/workflows/grumphp.yml | 10 ++++++---- appveyor.yml | 8 +++++--- composer.json | 22 +++++++++++----------- resources/config/util.yml | 1 + 5 files changed, 24 insertions(+), 19 deletions(-) diff --git a/.github/workflows/depsreview.yaml b/.github/workflows/depsreview.yaml index a25de591..da99d0c5 100644 --- a/.github/workflows/depsreview.yaml +++ b/.github/workflows/depsreview.yaml @@ -11,4 +11,4 @@ jobs: - name: 'Checkout Repository' uses: actions/checkout@v3 - name: 'Dependency Review' - uses: actions/dependency-review-action@v2 + uses: actions/dependency-review-action@v3 diff --git a/.github/workflows/grumphp.yml b/.github/workflows/grumphp.yml index 5c6ee6b3..ad49a461 100644 --- a/.github/workflows/grumphp.yml +++ b/.github/workflows/grumphp.yml @@ -10,7 +10,7 @@ jobs: strategy: matrix: operating-system: [ubuntu-latest, macos-latest] #windows-latest currently not working - php-versions: ['7.4', '8.0', '8.1'] + php-versions: ['8.0', '8.1', '8.2'] composer-options: ['', '--prefer-lowest'] composer-versions: ['composer:v2'] fail-fast: false @@ -39,14 +39,16 @@ jobs: key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} restore-keys: ${{ runner.os }}-composer- - name: Install dependencies + if: matrix.php-versions != '8.2' run: composer update --prefer-dist --no-progress --no-suggest ${{ matrix.composer-options }} -# - name: Install dependencies (Ignore platform) -# if: matrix.php-versions == '8.1' -# run: composer update --prefer-dist --no-progress --no-suggest ${{ matrix.composer-options }} --ignore-platform-req=php + - name: Install dependencies (Ignore platform) + if: matrix.php-versions == '8.2' + run: composer update --prefer-dist --no-progress --no-suggest ${{ matrix.composer-options }} --ignore-platform-req=php+ - name: Set git variables run: | git config --global user.email "you@example.com" git config --global user.name "Your Name" + git config --global protocol.file.allow always - name: Run the tests on Windows if: runner.os == 'Windows' run: php vendor/bin/grumphp run --no-interaction --testsuite=windows diff --git a/appveyor.yml b/appveyor.yml index 06e3e2b8..6e86b019 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -7,16 +7,17 @@ platform: #matrix: # allow_failures: -# - php_version: 8.1 +# - php_version: 8.2 environment: matrix: +# TODO : NOT AVAILABLE YET ! +# - dependencies: highest +# php_version: 8.2 - dependencies: highest php_version: 8.1 - dependencies: highest php_version: 8.0 - - dependencies: highest - php_version: 7.4 project_directory: c:\projects\grumphp composer_directory: c:\tools\composer @@ -71,6 +72,7 @@ install: - IF %dependencies%==highest composer update --prefer-dist --no-progress --no-scripts --no-suggest --profile - git config --global user.email "doesntmatter@dispostable.com" - git config --global user.name "GrumPHP" + - git config --global protocol.file.allow always test_script: - ps: cd $Env:project_directory diff --git a/composer.json b/composer.json index 44da6a20..3605b44a 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ } ], "require": { - "php": "^7.4 || ^8.0", + "php": "^8.0", "ext-json": "*", "composer-plugin-api": "~2.0", "amphp/amp": "^2.6", @@ -27,16 +27,16 @@ "ondram/ci-detector": "^4.0", "psr/container": "^1.1 || ^2.0", "seld/jsonlint": "~1.8", - "symfony/config": "~5.3 || ~6.0", - "symfony/console": "~5.3 || ~6.0", - "symfony/dependency-injection": "~5.3 || ~6.0", - "symfony/dotenv": "~5.3 || ~6.0", - "symfony/event-dispatcher": "~5.3 || ~6.0", - "symfony/filesystem": "~5.3 || ~6.0", - "symfony/finder": "~5.3 || ~6.0", - "symfony/options-resolver": "~5.3 || ~6.0", - "symfony/process": "~5.3 || ~6.0", - "symfony/yaml": "~5.3 || ~6.0" + "symfony/config": "~5.4 || ~6.0", + "symfony/console": "~5.4 || ~6.0", + "symfony/dependency-injection": "~5.4 || ~6.0", + "symfony/dotenv": "~5.4 || ~6.0", + "symfony/event-dispatcher": "~5.4 || ~6.0", + "symfony/filesystem": "~5.4 || ~6.0", + "symfony/finder": "~5.4 || ~6.0", + "symfony/options-resolver": "~5.4 || ~6.0", + "symfony/process": "~5.4 || ~6.0", + "symfony/yaml": "~5.4 || ~6.0" }, "require-dev": { "amphp/sync": "^v1.4", diff --git a/resources/config/util.yml b/resources/config/util.yml index 4f1fbff9..f95d87fe 100644 --- a/resources/config/util.yml +++ b/resources/config/util.yml @@ -21,3 +21,4 @@ services: '7.4': '2022-11-28 23:59:59' '8.0': '2023-11-26 23:59:59' '8.1': '2024-11-25 23:59:59' + '8.2': '2025-12-08 23:59:59' From b8252a4714d3c06bc8180d3db4ffabe6144db479 Mon Sep 17 00:00:00 2001 From: Toon Verwerft Date: Fri, 25 Nov 2022 09:51:01 +0100 Subject: [PATCH 25/37] 1.14.0 release --- src/Console/ApplicationConfigurator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Console/ApplicationConfigurator.php b/src/Console/ApplicationConfigurator.php index 42aeaa60..40cb082d 100644 --- a/src/Console/ApplicationConfigurator.php +++ b/src/Console/ApplicationConfigurator.php @@ -10,7 +10,7 @@ class ApplicationConfigurator { const APP_NAME = 'GrumPHP'; - const APP_VERSION = '1.13.0'; + const APP_VERSION = '1.14.0'; public function configure(Application $application): void { From 49df1fe7b553f25bd4e830766ada64b6d720c7ee Mon Sep 17 00:00:00 2001 From: Alessandro Aussems Date: Fri, 28 Oct 2022 14:39:04 +0200 Subject: [PATCH 26/37] Add Rector Task Update docs Register Task Fix ansi argument Make clear-cache true by default Make no-progress-bar true by default Remove xdebug option Add Rector Task --- composer.json | 1 + doc/tasks.md | 4 +- doc/tasks/rector.md | 64 ++++++++++++ resources/config/tasks.yml | 7 ++ src/Task/Rector.php | 89 ++++++++++++++++ test/Unit/Task/RectorTest.php | 189 ++++++++++++++++++++++++++++++++++ 6 files changed, 353 insertions(+), 1 deletion(-) create mode 100644 doc/tasks/rector.md create mode 100644 src/Task/Rector.php create mode 100644 test/Unit/Task/RectorTest.php diff --git a/composer.json b/composer.json index 5ca87327..1021a821 100644 --- a/composer.json +++ b/composer.json @@ -75,6 +75,7 @@ "phpstan/phpstan": "Lets GrumPHP discover bugs in your code without running it.", "phpunit/phpunit": "Lets GrumPHP run your unit tests.", "povils/phpmnd": "Lets GrumPHP help you detect magic numbers in PHP code.", + "rectorphp/rector ": "Lets GrumPHP instantly upgrade and automatically refactor your PHP code.", "roave/security-advisories": "Lets GrumPHP be sure that there are no known security issues.", "sebastian/phpcpd": "Lets GrumPHP find duplicated code.", "squizlabs/php_codesniffer": "Lets GrumPHP sniff on your code.", diff --git a/doc/tasks.md b/doc/tasks.md index 6d69d750..072d0933 100644 --- a/doc/tasks.md +++ b/doc/tasks.md @@ -51,7 +51,8 @@ grumphp: phpunitbridge: ~ phpversion: ~ progpilot: ~ - psalm: ~ + psalm: ~ + rector: ~ robo: ~ securitychecker_enlightn: ~ securitychecker_local: ~ @@ -115,6 +116,7 @@ Every task has its own default configuration. It is possible to overwrite the pa - [PhpVersion](tasks/phpversion.md) - [Progpilot](tasks/progpilot.md) - [Psalm](tasks/psalm.md) +- [Rector](tasks/rector.md) - [Robo](tasks/robo.md) - [Security Checker](tasks/securitychecker.md) - [Enlightn](tasks/securitychecker/enlightn.md) diff --git a/doc/tasks/rector.md b/doc/tasks/rector.md new file mode 100644 index 00000000..1c55a7a0 --- /dev/null +++ b/doc/tasks/rector.md @@ -0,0 +1,64 @@ +# Rector + +Rector is a tool to instantly upgrade and automatically refactor your PHP 5.3+ code. +It lives under the `rector` namespace and has following configurable parameters: + +## Composer +```bash +composer require --dev rectorphp/rector +``` + +## Config +```yaml +# grumphp.yml +grumphp: + tasks: + rector: + config: rector.php + triggered_by: ['php'] + ignore_patterns: [] + clear-cache: true + no-progress-bar: true + no-diffs: false +``` + +**config** + +*Default: rector.php* + +With this parameter you can specify the path your project's configuration file. + +**triggered_by** + +*Default: [php]* + +This is a list of extensions to be sniffed. + + +**ignore_patterns** + +*Default: []* + +This is a list of patterns that will be ignored by Rector. With this option you can skip files like +tests. Leave this option blank to run Rector for every php file/directory specified in your +configuration. + + +**clear-cache** + +*Default: true* + +With this parameter you can run Rector without using the cache. + +**no-progress-bar** + +*Default: true* + +With this parameter you can run Rector without showing the progress bar. + +**no-diffs** + +*Default: false* + +With this parameter you can run Rector without showing file diffs. + diff --git a/resources/config/tasks.yml b/resources/config/tasks.yml index 8f11d851..d459ce1a 100644 --- a/resources/config/tasks.yml +++ b/resources/config/tasks.yml @@ -315,6 +315,13 @@ services: tags: - {name: grumphp.task, task: psalm} + GrumPHP\Task\Rector: + arguments: + - '@process_builder' + - '@formatter.raw_process' + tags: + - { name: grumphp.task, task: rector } + GrumPHP\Task\Robo: arguments: - '@process_builder' diff --git a/src/Task/Rector.php b/src/Task/Rector.php new file mode 100644 index 00000000..d5eea24a --- /dev/null +++ b/src/Task/Rector.php @@ -0,0 +1,89 @@ +setDefaults([ + 'config' => 'rector.php', + 'triggered_by' => ['php'], + 'ignore_patterns' => [], + 'clear-cache' => true, + 'no-progress-bar' => true, + 'no-diffs' => false, + ]); + + $resolver->addAllowedTypes('config', ['null', 'string']); + $resolver->addAllowedTypes('triggered_by', ['array']); + $resolver->addAllowedTypes('ignore_patterns', ['array']); + $resolver->addAllowedTypes('clear-cache', ['bool']); + $resolver->addAllowedTypes('no-progress-bar', ['bool']); + $resolver->addAllowedTypes('no-diffs', ['bool']); + + return $resolver; + } + + public function canRunInContext(ContextInterface $context): bool + { + return $context instanceof RunContext || $context instanceof GitPreCommitContext; + } + + public function run(ContextInterface $context): TaskResultInterface + { + $config = $this->getConfig()->getOptions(); + + $files = $context + ->getFiles() + ->notPaths($config['ignore_patterns']) + ->extensions($config['triggered_by']); + + if (0 === \count($files)) { + return TaskResult::createSkipped($this, $context); + } + + $arguments = $this->processBuilder->createArgumentsForCommand('rector'); + $arguments->add('process'); + $arguments->add('--dry-run'); + $arguments->add('--ansi'); + + $arguments->addOptionalArgument('--config=%s', $config['config']); + $arguments->addOptionalArgument('--clear-cache', $config['clear-cache']); + $arguments->addOptionalArgument('--no-progress-bar', $config['no-progress-bar']); + $arguments->addOptionalArgument('--no-diffs', $config['no-diffs']); + + if ($context instanceof GitPreCommitContext) { + $arguments->addFiles($files); + } + + $process = $this->processBuilder->buildProcess($arguments); + $process->run(); + + if (!$process->isSuccessful()) { + return FixableProcessResultProvider::provide( + TaskResult::createFailed($this, $context, $this->formatter->format($process)), + function () use ($arguments): Process { + $arguments->add('--clear-cache'); + $arguments->removeElement('--dry-run'); + + return $this->processBuilder->buildProcess($arguments); + } + ); + } + + return TaskResult::createPassed($this, $context); + } +} diff --git a/test/Unit/Task/RectorTest.php b/test/Unit/Task/RectorTest.php new file mode 100644 index 00000000..051f5432 --- /dev/null +++ b/test/Unit/Task/RectorTest.php @@ -0,0 +1,189 @@ +formatter = $this->prophesize(RawProcessFormatter::class); + + return new Rector( + $this->processBuilder->reveal(), + $this->formatter->reveal() + ); + } + + public function provideConfigurableOptions(): iterable + { + yield 'defaults' => [ + [], + [ + 'config' => 'rector.php', + 'triggered_by' => ['php'], + 'ignore_patterns' => [], + 'clear-cache' => true, + 'no-progress-bar' => true, + 'no-diffs' => false, + ] + ]; + } + + public function provideRunContexts(): iterable + { + yield 'run-context' => [ + true, + $this->mockContext(RunContext::class) + ]; + + yield 'pre-commit-context' => [ + true, + $this->mockContext(GitPreCommitContext::class) + ]; + + yield 'other' => [ + false, + $this->mockContext() + ]; + } + + public function provideFailsOnStuff(): iterable + { + yield 'exitCode1' => [ + [], + $this->mockContext(RunContext::class, ['hello.php']), + function () { + $this->mockProcessBuilder('rector', $process = $this->mockProcess(1)); + + $this->formatter->format($process)->willReturn($message = 'message'); + }, + 'message', + FixableTaskResult::class + ]; + } + + public function providePassesOnStuff(): iterable + { + yield 'exitCode0' => [ + [], + $this->mockContext(RunContext::class, ['hello.php']), + function () { + $this->mockProcessBuilder('rector', $this->mockProcess(0)); + } + ]; + } + + public function provideSkipsOnStuff(): iterable + { + yield 'no-files' => [ + [], + $this->mockContext(RunContext::class), + function () {} + ]; + yield 'no-files-after-triggered-by' => [ + [], + $this->mockContext(RunContext::class, ['notaphpfile.txt']), + function () {} + ]; + yield 'no-files-after-ignore-patterns' => [ + [ + 'ignore_patterns' => ['test/'], + ], + $this->mockContext(RunContext::class, ['test/file.php']), + function () {} + ]; + } + + public function provideExternalTaskRuns(): iterable + { + yield 'defaults' => [ + [], + $this->mockContext(RunContext::class, ['hello.php', 'hello2.php']), + 'rector', + [ + 'process', + '--dry-run', + '--ansi', + '--config=rector.php', + '--clear-cache', + '--no-progress-bar', + ] + ]; + yield 'config' => [ + [ + 'config' => 'rector-config.php', + ], + $this->mockContext(RunContext::class, ['hello.php', 'hello2.php']), + 'rector', + [ + 'process', + '--dry-run', + '--ansi', + '--config=rector-config.php', + '--clear-cache', + '--no-progress-bar', + ] + ]; + yield 'no-clear-cache' => [ + [ + 'clear-cache' => false, + ], + $this->mockContext(RunContext::class, ['hello.php', 'hello2.php']), + 'rector', + [ + 'process', + '--dry-run', + '--ansi', + '--config=rector.php', + '--no-progress-bar', + ] + ]; + yield 'progress-bar' => [ + [ + 'no-progress-bar' => false, + ], + $this->mockContext(RunContext::class, ['hello.php', 'hello2.php']), + 'rector', + [ + 'process', + '--dry-run', + '--ansi', + '--config=rector.php', + '--clear-cache', + ] + ]; + yield 'no-diffs' => [ + [ + 'no-diffs' => true, + ], + $this->mockContext(RunContext::class, ['hello.php', 'hello2.php']), + 'rector', + [ + 'process', + '--dry-run', + '--ansi', + '--config=rector.php', + '--clear-cache', + '--no-progress-bar', + '--no-diffs' + ] + ]; + } +} From d3e6a7ab084785fd2b1b6d51717bef09fbabeb3d Mon Sep 17 00:00:00 2001 From: Alessandro Aussems Date: Fri, 25 Nov 2022 10:38:35 +0100 Subject: [PATCH 27/37] Update config to use snake_case --- doc/tasks/rector.md | 12 ++++++------ src/Task/Rector.php | 18 +++++++++--------- test/Unit/Task/RectorTest.php | 12 ++++++------ 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/doc/tasks/rector.md b/doc/tasks/rector.md index 1c55a7a0..ff9a7716 100644 --- a/doc/tasks/rector.md +++ b/doc/tasks/rector.md @@ -17,9 +17,9 @@ grumphp: config: rector.php triggered_by: ['php'] ignore_patterns: [] - clear-cache: true - no-progress-bar: true - no-diffs: false + clear_cache: true + no_progress_bar: true + no_diffs: false ``` **config** @@ -44,19 +44,19 @@ tests. Leave this option blank to run Rector for every php file/directory specif configuration. -**clear-cache** +**clear_cache** *Default: true* With this parameter you can run Rector without using the cache. -**no-progress-bar** +**no_progress_bar** *Default: true* With this parameter you can run Rector without showing the progress bar. -**no-diffs** +**no_diffs** *Default: false* diff --git a/src/Task/Rector.php b/src/Task/Rector.php index d5eea24a..10a5991f 100644 --- a/src/Task/Rector.php +++ b/src/Task/Rector.php @@ -22,17 +22,17 @@ public static function getConfigurableOptions(): OptionsResolver 'config' => 'rector.php', 'triggered_by' => ['php'], 'ignore_patterns' => [], - 'clear-cache' => true, - 'no-progress-bar' => true, - 'no-diffs' => false, + 'clear_cache' => true, + 'no_progress_bar' => true, + 'no_diffs' => false, ]); $resolver->addAllowedTypes('config', ['null', 'string']); $resolver->addAllowedTypes('triggered_by', ['array']); $resolver->addAllowedTypes('ignore_patterns', ['array']); - $resolver->addAllowedTypes('clear-cache', ['bool']); - $resolver->addAllowedTypes('no-progress-bar', ['bool']); - $resolver->addAllowedTypes('no-diffs', ['bool']); + $resolver->addAllowedTypes('clear_cache', ['bool']); + $resolver->addAllowedTypes('no_progress_bar', ['bool']); + $resolver->addAllowedTypes('no_diffs', ['bool']); return $resolver; } @@ -61,9 +61,9 @@ public function run(ContextInterface $context): TaskResultInterface $arguments->add('--ansi'); $arguments->addOptionalArgument('--config=%s', $config['config']); - $arguments->addOptionalArgument('--clear-cache', $config['clear-cache']); - $arguments->addOptionalArgument('--no-progress-bar', $config['no-progress-bar']); - $arguments->addOptionalArgument('--no-diffs', $config['no-diffs']); + $arguments->addOptionalArgument('--clear-cache', $config['clear_cache']); + $arguments->addOptionalArgument('--no-progress-bar', $config['no_progress_bar']); + $arguments->addOptionalArgument('--no-diffs', $config['no_diffs']); if ($context instanceof GitPreCommitContext) { $arguments->addFiles($files); diff --git a/test/Unit/Task/RectorTest.php b/test/Unit/Task/RectorTest.php index 051f5432..7ac7decd 100644 --- a/test/Unit/Task/RectorTest.php +++ b/test/Unit/Task/RectorTest.php @@ -39,9 +39,9 @@ public function provideConfigurableOptions(): iterable 'config' => 'rector.php', 'triggered_by' => ['php'], 'ignore_patterns' => [], - 'clear-cache' => true, - 'no-progress-bar' => true, - 'no-diffs' => false, + 'clear_cache' => true, + 'no_progress_bar' => true, + 'no_diffs' => false, ] ]; } @@ -143,7 +143,7 @@ public function provideExternalTaskRuns(): iterable ]; yield 'no-clear-cache' => [ [ - 'clear-cache' => false, + 'clear_cache' => false, ], $this->mockContext(RunContext::class, ['hello.php', 'hello2.php']), 'rector', @@ -157,7 +157,7 @@ public function provideExternalTaskRuns(): iterable ]; yield 'progress-bar' => [ [ - 'no-progress-bar' => false, + 'no_progress_bar' => false, ], $this->mockContext(RunContext::class, ['hello.php', 'hello2.php']), 'rector', @@ -171,7 +171,7 @@ public function provideExternalTaskRuns(): iterable ]; yield 'no-diffs' => [ [ - 'no-diffs' => true, + 'no_diffs' => true, ], $this->mockContext(RunContext::class, ['hello.php', 'hello2.php']), 'rector', From 9181a1db8011f50578e5c64fe397d9fdd30aa33a Mon Sep 17 00:00:00 2001 From: Alessandro Aussems Date: Fri, 25 Nov 2022 10:43:18 +0100 Subject: [PATCH 28/37] Removed --ansi argument --- src/Task/Rector.php | 1 - test/Unit/Task/RectorTest.php | 5 ----- 2 files changed, 6 deletions(-) diff --git a/src/Task/Rector.php b/src/Task/Rector.php index 10a5991f..9b0b4cf4 100644 --- a/src/Task/Rector.php +++ b/src/Task/Rector.php @@ -58,7 +58,6 @@ public function run(ContextInterface $context): TaskResultInterface $arguments = $this->processBuilder->createArgumentsForCommand('rector'); $arguments->add('process'); $arguments->add('--dry-run'); - $arguments->add('--ansi'); $arguments->addOptionalArgument('--config=%s', $config['config']); $arguments->addOptionalArgument('--clear-cache', $config['clear_cache']); diff --git a/test/Unit/Task/RectorTest.php b/test/Unit/Task/RectorTest.php index 7ac7decd..7fb97328 100644 --- a/test/Unit/Task/RectorTest.php +++ b/test/Unit/Task/RectorTest.php @@ -120,7 +120,6 @@ public function provideExternalTaskRuns(): iterable [ 'process', '--dry-run', - '--ansi', '--config=rector.php', '--clear-cache', '--no-progress-bar', @@ -135,7 +134,6 @@ public function provideExternalTaskRuns(): iterable [ 'process', '--dry-run', - '--ansi', '--config=rector-config.php', '--clear-cache', '--no-progress-bar', @@ -150,7 +148,6 @@ public function provideExternalTaskRuns(): iterable [ 'process', '--dry-run', - '--ansi', '--config=rector.php', '--no-progress-bar', ] @@ -164,7 +161,6 @@ public function provideExternalTaskRuns(): iterable [ 'process', '--dry-run', - '--ansi', '--config=rector.php', '--clear-cache', ] @@ -178,7 +174,6 @@ public function provideExternalTaskRuns(): iterable [ 'process', '--dry-run', - '--ansi', '--config=rector.php', '--clear-cache', '--no-progress-bar', From e2b3648c6076eb68b7e231ec18965fce9f403144 Mon Sep 17 00:00:00 2001 From: Alessandro Aussems Date: Fri, 25 Nov 2022 10:49:17 +0100 Subject: [PATCH 29/37] Make config option 'null' by default --- doc/tasks/rector.md | 6 +++--- src/Task/Rector.php | 2 +- test/Unit/Task/RectorTest.php | 6 +----- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/doc/tasks/rector.md b/doc/tasks/rector.md index ff9a7716..ae0b82c2 100644 --- a/doc/tasks/rector.md +++ b/doc/tasks/rector.md @@ -14,7 +14,7 @@ composer require --dev rectorphp/rector grumphp: tasks: rector: - config: rector.php + config: null triggered_by: ['php'] ignore_patterns: [] clear_cache: true @@ -24,9 +24,9 @@ grumphp: **config** -*Default: rector.php* +*Default: null* -With this parameter you can specify the path your project's configuration file. +With this parameter you can specify the path your project's configuration file. When 'null' rector will run with the default file: rector.php **triggered_by** diff --git a/src/Task/Rector.php b/src/Task/Rector.php index 9b0b4cf4..35a050a0 100644 --- a/src/Task/Rector.php +++ b/src/Task/Rector.php @@ -19,7 +19,7 @@ public static function getConfigurableOptions(): OptionsResolver { $resolver = new OptionsResolver(); $resolver->setDefaults([ - 'config' => 'rector.php', + 'config' => null, 'triggered_by' => ['php'], 'ignore_patterns' => [], 'clear_cache' => true, diff --git a/test/Unit/Task/RectorTest.php b/test/Unit/Task/RectorTest.php index 7fb97328..0632a321 100644 --- a/test/Unit/Task/RectorTest.php +++ b/test/Unit/Task/RectorTest.php @@ -36,7 +36,7 @@ public function provideConfigurableOptions(): iterable yield 'defaults' => [ [], [ - 'config' => 'rector.php', + 'config' => null, 'triggered_by' => ['php'], 'ignore_patterns' => [], 'clear_cache' => true, @@ -120,7 +120,6 @@ public function provideExternalTaskRuns(): iterable [ 'process', '--dry-run', - '--config=rector.php', '--clear-cache', '--no-progress-bar', ] @@ -148,7 +147,6 @@ public function provideExternalTaskRuns(): iterable [ 'process', '--dry-run', - '--config=rector.php', '--no-progress-bar', ] ]; @@ -161,7 +159,6 @@ public function provideExternalTaskRuns(): iterable [ 'process', '--dry-run', - '--config=rector.php', '--clear-cache', ] ]; @@ -174,7 +171,6 @@ public function provideExternalTaskRuns(): iterable [ 'process', '--dry-run', - '--config=rector.php', '--clear-cache', '--no-progress-bar', '--no-diffs' From a5969cc3fd0905e29d36570fd3848016a248677f Mon Sep 17 00:00:00 2001 From: Alessandro Aussems Date: Fri, 25 Nov 2022 10:52:38 +0100 Subject: [PATCH 30/37] Remove no_progress_bar option --- doc/tasks/rector.md | 7 ------- src/Task/Rector.php | 4 +--- test/Unit/Task/RectorTest.php | 19 +++---------------- 3 files changed, 4 insertions(+), 26 deletions(-) diff --git a/doc/tasks/rector.md b/doc/tasks/rector.md index ae0b82c2..8087d7e2 100644 --- a/doc/tasks/rector.md +++ b/doc/tasks/rector.md @@ -18,7 +18,6 @@ grumphp: triggered_by: ['php'] ignore_patterns: [] clear_cache: true - no_progress_bar: true no_diffs: false ``` @@ -50,12 +49,6 @@ configuration. With this parameter you can run Rector without using the cache. -**no_progress_bar** - -*Default: true* - -With this parameter you can run Rector without showing the progress bar. - **no_diffs** *Default: false* diff --git a/src/Task/Rector.php b/src/Task/Rector.php index 35a050a0..11997d59 100644 --- a/src/Task/Rector.php +++ b/src/Task/Rector.php @@ -23,7 +23,6 @@ public static function getConfigurableOptions(): OptionsResolver 'triggered_by' => ['php'], 'ignore_patterns' => [], 'clear_cache' => true, - 'no_progress_bar' => true, 'no_diffs' => false, ]); @@ -31,7 +30,6 @@ public static function getConfigurableOptions(): OptionsResolver $resolver->addAllowedTypes('triggered_by', ['array']); $resolver->addAllowedTypes('ignore_patterns', ['array']); $resolver->addAllowedTypes('clear_cache', ['bool']); - $resolver->addAllowedTypes('no_progress_bar', ['bool']); $resolver->addAllowedTypes('no_diffs', ['bool']); return $resolver; @@ -58,10 +56,10 @@ public function run(ContextInterface $context): TaskResultInterface $arguments = $this->processBuilder->createArgumentsForCommand('rector'); $arguments->add('process'); $arguments->add('--dry-run'); + $arguments->add('--no-progress-bar'); $arguments->addOptionalArgument('--config=%s', $config['config']); $arguments->addOptionalArgument('--clear-cache', $config['clear_cache']); - $arguments->addOptionalArgument('--no-progress-bar', $config['no_progress_bar']); $arguments->addOptionalArgument('--no-diffs', $config['no_diffs']); if ($context instanceof GitPreCommitContext) { diff --git a/test/Unit/Task/RectorTest.php b/test/Unit/Task/RectorTest.php index 0632a321..c133f2e5 100644 --- a/test/Unit/Task/RectorTest.php +++ b/test/Unit/Task/RectorTest.php @@ -40,7 +40,6 @@ public function provideConfigurableOptions(): iterable 'triggered_by' => ['php'], 'ignore_patterns' => [], 'clear_cache' => true, - 'no_progress_bar' => true, 'no_diffs' => false, ] ]; @@ -120,8 +119,8 @@ public function provideExternalTaskRuns(): iterable [ 'process', '--dry-run', - '--clear-cache', '--no-progress-bar', + '--clear-cache', ] ]; yield 'config' => [ @@ -133,9 +132,9 @@ public function provideExternalTaskRuns(): iterable [ 'process', '--dry-run', + '--no-progress-bar', '--config=rector-config.php', '--clear-cache', - '--no-progress-bar', ] ]; yield 'no-clear-cache' => [ @@ -150,18 +149,6 @@ public function provideExternalTaskRuns(): iterable '--no-progress-bar', ] ]; - yield 'progress-bar' => [ - [ - 'no_progress_bar' => false, - ], - $this->mockContext(RunContext::class, ['hello.php', 'hello2.php']), - 'rector', - [ - 'process', - '--dry-run', - '--clear-cache', - ] - ]; yield 'no-diffs' => [ [ 'no_diffs' => true, @@ -171,8 +158,8 @@ public function provideExternalTaskRuns(): iterable [ 'process', '--dry-run', - '--clear-cache', '--no-progress-bar', + '--clear-cache', '--no-diffs' ] ]; From b19ff26d42e6223243838bc57e7d8228bb9f43d5 Mon Sep 17 00:00:00 2001 From: Alessandro Aussems Date: Fri, 25 Nov 2022 11:02:18 +0100 Subject: [PATCH 31/37] Re-add --ansi option --- src/Task/Rector.php | 1 + test/Unit/Task/RectorTest.php | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/src/Task/Rector.php b/src/Task/Rector.php index 11997d59..2549ac27 100644 --- a/src/Task/Rector.php +++ b/src/Task/Rector.php @@ -56,6 +56,7 @@ public function run(ContextInterface $context): TaskResultInterface $arguments = $this->processBuilder->createArgumentsForCommand('rector'); $arguments->add('process'); $arguments->add('--dry-run'); + $arguments->add('--ansi'); $arguments->add('--no-progress-bar'); $arguments->addOptionalArgument('--config=%s', $config['config']); diff --git a/test/Unit/Task/RectorTest.php b/test/Unit/Task/RectorTest.php index c133f2e5..33e4ebc8 100644 --- a/test/Unit/Task/RectorTest.php +++ b/test/Unit/Task/RectorTest.php @@ -119,6 +119,7 @@ public function provideExternalTaskRuns(): iterable [ 'process', '--dry-run', + '--ansi', '--no-progress-bar', '--clear-cache', ] @@ -132,6 +133,7 @@ public function provideExternalTaskRuns(): iterable [ 'process', '--dry-run', + '--ansi', '--no-progress-bar', '--config=rector-config.php', '--clear-cache', @@ -146,6 +148,7 @@ public function provideExternalTaskRuns(): iterable [ 'process', '--dry-run', + '--ansi', '--no-progress-bar', ] ]; @@ -158,6 +161,7 @@ public function provideExternalTaskRuns(): iterable [ 'process', '--dry-run', + '--ansi', '--no-progress-bar', '--clear-cache', '--no-diffs' From f468f1cd7d7ed5d91de26744606ac716cf2f693e Mon Sep 17 00:00:00 2001 From: Alessandro Aussems Date: Fri, 25 Nov 2022 11:41:27 +0100 Subject: [PATCH 32/37] Remove --no-cache when fixing --- src/Task/Rector.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Task/Rector.php b/src/Task/Rector.php index 2549ac27..7a50bd53 100644 --- a/src/Task/Rector.php +++ b/src/Task/Rector.php @@ -74,7 +74,6 @@ public function run(ContextInterface $context): TaskResultInterface return FixableProcessResultProvider::provide( TaskResult::createFailed($this, $context, $this->formatter->format($process)), function () use ($arguments): Process { - $arguments->add('--clear-cache'); $arguments->removeElement('--dry-run'); return $this->processBuilder->buildProcess($arguments); From 762f741ddb69e6172c94817c46b4b4da5167dfe5 Mon Sep 17 00:00:00 2001 From: Ion Bazan Date: Tue, 29 Nov 2022 14:42:59 +0800 Subject: [PATCH 33/37] Fix invalid Rector install command --- doc/tasks/rector.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/tasks/rector.md b/doc/tasks/rector.md index 8087d7e2..ff780697 100644 --- a/doc/tasks/rector.md +++ b/doc/tasks/rector.md @@ -5,7 +5,7 @@ It lives under the `rector` namespace and has following configurable parameters: ## Composer ```bash -composer require --dev rectorphp/rector +composer require --dev rector/rector ``` ## Config From 90c429deb62dbfc61b65573bf0f44f7ed6687450 Mon Sep 17 00:00:00 2001 From: Toon Verwerft Date: Tue, 29 Nov 2022 08:16:26 +0100 Subject: [PATCH 34/37] Update rector suggestion See #1057 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 699f5bb5..dc656f30 100644 --- a/composer.json +++ b/composer.json @@ -75,7 +75,7 @@ "phpstan/phpstan": "Lets GrumPHP discover bugs in your code without running it.", "phpunit/phpunit": "Lets GrumPHP run your unit tests.", "povils/phpmnd": "Lets GrumPHP help you detect magic numbers in PHP code.", - "rectorphp/rector ": "Lets GrumPHP instantly upgrade and automatically refactor your PHP code.", + "rector/rector ": "Lets GrumPHP instantly upgrade and automatically refactor your PHP code.", "roave/security-advisories": "Lets GrumPHP be sure that there are no known security issues.", "sebastian/phpcpd": "Lets GrumPHP find duplicated code.", "squizlabs/php_codesniffer": "Lets GrumPHP sniff on your code.", From 69a774e992df15eed6729e1db683b8bb25923ec9 Mon Sep 17 00:00:00 2001 From: Melvin Date: Fri, 16 Dec 2022 17:45:50 +0100 Subject: [PATCH 35/37] Adding PHPCS specific rule (-s) to display which rule triggered the error --- doc/tasks/phpcs.md | 8 +++++++- src/Task/Phpcs.php | 3 +++ test/Unit/Task/PhpcsTest.php | 27 +++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/doc/tasks/phpcs.md b/doc/tasks/phpcs.md index dd39b828..cdc471fe 100644 --- a/doc/tasks/phpcs.md +++ b/doc/tasks/phpcs.md @@ -30,7 +30,7 @@ grumphp: sniffs: [] triggered_by: [php] exclude: [] - + show_sniffs_error_path: true ``` **standard** @@ -130,6 +130,12 @@ This is a list of extensions to be sniffed. This list is also passed to phpcs us A list of rules that should not be checked. Leave this option blank to run all configured rules for the selected standard. +**show_sniffs_error_path** + +*Default: true* + +Displays the sniff that triggered the error, allowing you to more easily find the specific rules with their namespaces. + ## Framework presets ### Symfony 2 diff --git a/src/Task/Phpcs.php b/src/Task/Phpcs.php index 885a277a..fa1abc6f 100644 --- a/src/Task/Phpcs.php +++ b/src/Task/Phpcs.php @@ -42,6 +42,7 @@ public static function getConfigurableOptions(): OptionsResolver 'report' => 'full', 'report_width' => null, 'exclude' => [], + 'show_sniffs_error_path' => true ]); $resolver->addAllowedTypes('standard', ['array', 'null', 'string']); @@ -57,6 +58,7 @@ public static function getConfigurableOptions(): OptionsResolver $resolver->addAllowedTypes('report', ['null', 'string']); $resolver->addAllowedTypes('report_width', ['null', 'int']); $resolver->addAllowedTypes('exclude', ['array']); + $resolver->addAllowedTypes('show_sniffs_error_path', ['bool']); return $resolver; } @@ -153,6 +155,7 @@ private function addArgumentsFromConfig( $arguments->addOptionalCommaSeparatedArgument('--sniffs=%s', $config['sniffs']); $arguments->addOptionalCommaSeparatedArgument('--ignore=%s', $config['ignore_patterns']); $arguments->addOptionalCommaSeparatedArgument('--exclude=%s', $config['exclude']); + $arguments->addOptionalArgument('-s', $config['show_sniffs_error_path']); return $arguments; } diff --git a/test/Unit/Task/PhpcsTest.php b/test/Unit/Task/PhpcsTest.php index 34e89f81..45c36cb1 100644 --- a/test/Unit/Task/PhpcsTest.php +++ b/test/Unit/Task/PhpcsTest.php @@ -49,6 +49,7 @@ public function provideConfigurableOptions(): iterable 'report' => 'full', 'report_width' => null, 'exclude' => [], + 'show_sniffs_error_path' => true ] ]; } @@ -160,6 +161,7 @@ public function provideExternalTaskRuns(): iterable [ '--extensions=php', '--report=full', + '-s', '--report-json', $this->expectFileList('hello.php'.PHP_EOL.'hello2.php'), ] @@ -174,6 +176,7 @@ public function provideExternalTaskRuns(): iterable '--standard=PSR1,PSR2', '--extensions=php', '--report=full', + '-s', '--report-json', $this->expectFileList('hello.php'.PHP_EOL.'hello2.php'), ] @@ -187,6 +190,7 @@ public function provideExternalTaskRuns(): iterable [ '--extensions=php,phtml', '--report=full', + '-s', '--report-json', $this->expectFileList('hello.php'.PHP_EOL.'hello2.php'), ] @@ -201,6 +205,7 @@ public function provideExternalTaskRuns(): iterable '--extensions=php', '--tab-width=4', '--report=full', + '-s', '--report-json', $this->expectFileList('hello.php'.PHP_EOL.'hello2.php'), ] @@ -215,6 +220,7 @@ public function provideExternalTaskRuns(): iterable '--extensions=php', '--encoding=UTF-8', '--report=full', + '-s', '--report-json', $this->expectFileList('hello.php'.PHP_EOL.'hello2.php'), ] @@ -228,6 +234,7 @@ public function provideExternalTaskRuns(): iterable [ '--extensions=php', '--report=small', + '-s', '--report-json', $this->expectFileList('hello.php'.PHP_EOL.'hello2.php'), ] @@ -242,6 +249,7 @@ public function provideExternalTaskRuns(): iterable '--extensions=php', '--report=full', '--report-width=20', + '-s', '--report-json', $this->expectFileList('hello.php'.PHP_EOL.'hello2.php'), ] @@ -256,6 +264,7 @@ public function provideExternalTaskRuns(): iterable '--extensions=php', '--report=full', '--severity=5', + '-s', '--report-json', $this->expectFileList('hello.php'.PHP_EOL.'hello2.php'), ] @@ -270,6 +279,7 @@ public function provideExternalTaskRuns(): iterable '--extensions=php', '--report=full', '--error-severity=5', + '-s', '--report-json', $this->expectFileList('hello.php'.PHP_EOL.'hello2.php'), ] @@ -284,6 +294,7 @@ public function provideExternalTaskRuns(): iterable '--extensions=php', '--report=full', '--warning-severity=5', + '-s', '--report-json', $this->expectFileList('hello.php'.PHP_EOL.'hello2.php'), ] @@ -298,6 +309,7 @@ public function provideExternalTaskRuns(): iterable '--extensions=php', '--report=full', '--sniffs=sniff1,sniff2', + '-s', '--report-json', $this->expectFileList('hello.php'.PHP_EOL.'hello2.php'), ] @@ -312,6 +324,7 @@ public function provideExternalTaskRuns(): iterable '--extensions=php', '--report=full', '--ignore=ignore1,ignore2', + '-s', '--report-json', $this->expectFileList('hello.php'.PHP_EOL.'hello2.php'), ] @@ -326,6 +339,20 @@ public function provideExternalTaskRuns(): iterable '--extensions=php', '--report=full', '--exclude=exclude1,exclude2', + '-s', + '--report-json', + $this->expectFileList('hello.php'.PHP_EOL.'hello2.php'), + ] + ]; + yield 's' => [ + [ + 'show_sniffs_error_path' => false + ], + $this->mockContext(RunContext::class, ['hello.php', 'hello2.php']), + 'phpcs', + [ + '--extensions=php', + '--report=full', '--report-json', $this->expectFileList('hello.php'.PHP_EOL.'hello2.php'), ] From 75b17349c9455325b4f98f4fc04a949bb2228689 Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Tue, 20 Dec 2022 11:56:46 +0100 Subject: [PATCH 36/37] Add support for doctrine/collections v2 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index dc656f30..20a26380 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ "amphp/amp": "^2.6", "amphp/parallel": "^1.4", "amphp/parallel-functions": "^1.1", - "doctrine/collections": "^1.6.8", + "doctrine/collections": "^1.6.8 || ^2.0", "gitonomy/gitlib": "^1.3", "laravel/serializable-closure": "^1.1", "monolog/monolog": "^2.0 || ^3.0", From 533e45484be80d426010a318ff6f99fbe33350a5 Mon Sep 17 00:00:00 2001 From: Toon Verwerft Date: Thu, 22 Dec 2022 13:36:10 +0100 Subject: [PATCH 37/37] 1.15.0 release --- src/Console/ApplicationConfigurator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Console/ApplicationConfigurator.php b/src/Console/ApplicationConfigurator.php index 40cb082d..963d191a 100644 --- a/src/Console/ApplicationConfigurator.php +++ b/src/Console/ApplicationConfigurator.php @@ -10,7 +10,7 @@ class ApplicationConfigurator { const APP_NAME = 'GrumPHP'; - const APP_VERSION = '1.14.0'; + const APP_VERSION = '1.15.0'; public function configure(Application $application): void {