From 5b667d513d3047715dec4eb41104a8509a7c99ca Mon Sep 17 00:00:00 2001 From: mscherer Date: Tue, 27 Dec 2022 22:49:05 +0100 Subject: [PATCH 1/6] Update for PHP 8.1+ --- .editorconfig | 3 +++ CakePHP/ruleset.xml | 3 +++ composer.json | 1 + phpstan.neon | 9 +++++++++ tests/phpstan_bootstrap.php | 8 ++++++++ 5 files changed, 24 insertions(+) create mode 100644 phpstan.neon create mode 100644 tests/phpstan_bootstrap.php diff --git a/.editorconfig b/.editorconfig index d7ec37b..b88269d 100644 --- a/.editorconfig +++ b/.editorconfig @@ -15,3 +15,6 @@ end_of_line = crlf [*.yml] indent_size = 2 + +[*.neon] +indent_style = tab diff --git a/CakePHP/ruleset.xml b/CakePHP/ruleset.xml index 95de8a9..a80b47c 100644 --- a/CakePHP/ruleset.xml +++ b/CakePHP/ruleset.xml @@ -96,6 +96,8 @@ + + @@ -141,6 +143,7 @@ */tests/* + diff --git a/composer.json b/composer.json index 1347fc2..94b755f 100644 --- a/composer.json +++ b/composer.json @@ -45,6 +45,7 @@ ], "cs-check": "phpcs --colors --parallel=16 -p -s CakePHP/", "cs-fix": "phpcbf --colors --parallel=16 -p CakePHP/", + "stan": "phpstan analyse", "docs": "php docs/generate.php", "explain": "phpcs -e --standard=CakePHP" } diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..e82ad2a --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,9 @@ +parameters: + level: 6 + paths: + - CakePHP/Sniffs/ + bootstrapFiles: + - %rootDir%/../../../tests/phpstan_bootstrap.php + ignoreErrors: + + checkMissingIterableValueType: false diff --git a/tests/phpstan_bootstrap.php b/tests/phpstan_bootstrap.php new file mode 100644 index 0000000..3cc86c5 --- /dev/null +++ b/tests/phpstan_bootstrap.php @@ -0,0 +1,8 @@ + Date: Sun, 1 Jan 2023 15:33:14 +0100 Subject: [PATCH 2/6] Update ruleset.xml --- CakePHP/ruleset.xml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/CakePHP/ruleset.xml b/CakePHP/ruleset.xml index a80b47c..fab5836 100644 --- a/CakePHP/ruleset.xml +++ b/CakePHP/ruleset.xml @@ -98,6 +98,22 @@ + + + + + + + + + + + + + + + + From 4670bf15834dfa96135b10629802faaa2e26e029 Mon Sep 17 00:00:00 2001 From: mscherer Date: Sat, 30 Nov 2024 04:42:06 +0100 Subject: [PATCH 3/6] Update docs. --- docs/README.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/docs/README.md b/docs/README.md index b42dfc2..7728ccb 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,6 +1,6 @@ # CakePHP ruleset -The CakePHP standard contains 147 sniffs +The CakePHP standard contains 152 sniffs CakePHP (20 sniffs) ------------------- @@ -95,7 +95,7 @@ PSR12 (17 sniffs) - PSR12.Properties.ConstantVisibility - PSR12.Traits.UseDeclaration -SlevomatCodingStandard (43 sniffs) +SlevomatCodingStandard (48 sniffs) ---------------------------------- - SlevomatCodingStandard.Arrays.TrailingArrayComma - SlevomatCodingStandard.Attributes.AttributeAndTargetSpacing @@ -116,7 +116,12 @@ SlevomatCodingStandard (43 sniffs) - SlevomatCodingStandard.ControlStructures.RequireNullCoalesceOperator - SlevomatCodingStandard.Exceptions.DeadCatch - SlevomatCodingStandard.Functions.ArrowFunctionDeclaration +- SlevomatCodingStandard.Functions.DisallowTrailingCommaInCall +- SlevomatCodingStandard.Functions.DisallowTrailingCommaInClosureUse +- SlevomatCodingStandard.Functions.DisallowTrailingCommaInDeclaration - SlevomatCodingStandard.Functions.RequireTrailingCommaInCall +- SlevomatCodingStandard.Functions.RequireTrailingCommaInClosureUse +- SlevomatCodingStandard.Functions.RequireTrailingCommaInDeclaration - SlevomatCodingStandard.Namespaces.AlphabeticallySortedUses - SlevomatCodingStandard.Namespaces.FullyQualifiedClassNameInAnnotation - SlevomatCodingStandard.Namespaces.NamespaceDeclaration From 009c78e58bd662bf068537d2e0cc51f15804911b Mon Sep 17 00:00:00 2001 From: mscherer Date: Sat, 30 Nov 2024 05:44:38 +0100 Subject: [PATCH 4/6] Add PHPStan. --- .github/workflows/ci.yml | 3 +++ CakePHP/Sniffs/Commenting/TypeHintSniff.php | 1 + composer.json | 1 + phpstan.neon | 3 +-- 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 46a44f0..dd060c2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -57,3 +57,6 @@ jobs: - name: Run PHP CodeSniffer run: vendor/bin/phpcs --report=checkstyle | cs2pr + + - name: Run PHPStan + run: vendor/bin/phpstan diff --git a/CakePHP/Sniffs/Commenting/TypeHintSniff.php b/CakePHP/Sniffs/Commenting/TypeHintSniff.php index 3e08854..ee7604a 100644 --- a/CakePHP/Sniffs/Commenting/TypeHintSniff.php +++ b/CakePHP/Sniffs/Commenting/TypeHintSniff.php @@ -101,6 +101,7 @@ public function process(File $phpcsFile, $stackPtr) continue; } + /** @phpstan-ignore-next-line */ if ($valueNode->type instanceof UnionTypeNode) { $types = $valueNode->type->types; } elseif ($valueNode->type instanceof ArrayTypeNode) { diff --git a/composer.json b/composer.json index 94b755f..78145a8 100644 --- a/composer.json +++ b/composer.json @@ -24,6 +24,7 @@ "squizlabs/php_codesniffer": "^3.9" }, "require-dev": { + "phpstan/phpstan": "^2.0.3", "phpunit/phpunit": "^9.3.4" }, "autoload": { diff --git a/phpstan.neon b/phpstan.neon index e82ad2a..bf0b10f 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -5,5 +5,4 @@ parameters: bootstrapFiles: - %rootDir%/../../../tests/phpstan_bootstrap.php ignoreErrors: - - checkMissingIterableValueType: false + - identifier: missingType.iterableValue From 1a3cfcfcdbe63ae86c7a677c388659c4ee35cc89 Mon Sep 17 00:00:00 2001 From: mscherer Date: Sat, 30 Nov 2024 05:54:12 +0100 Subject: [PATCH 5/6] Add NamedArgumentSpacing sniff. --- CakePHP/ruleset.xml | 18 +++++++++--------- docs/README.md | 5 +++-- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/CakePHP/ruleset.xml b/CakePHP/ruleset.xml index fab5836..3372d0d 100644 --- a/CakePHP/ruleset.xml +++ b/CakePHP/ruleset.xml @@ -133,17 +133,17 @@ - - - - - + + + + + - + @@ -232,13 +232,13 @@ - + - + + - diff --git a/docs/README.md b/docs/README.md index 7728ccb..c3d7cf4 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,6 +1,6 @@ # CakePHP ruleset -The CakePHP standard contains 152 sniffs +The CakePHP standard contains 153 sniffs CakePHP (20 sniffs) ------------------- @@ -95,7 +95,7 @@ PSR12 (17 sniffs) - PSR12.Properties.ConstantVisibility - PSR12.Traits.UseDeclaration -SlevomatCodingStandard (48 sniffs) +SlevomatCodingStandard (49 sniffs) ---------------------------------- - SlevomatCodingStandard.Arrays.TrailingArrayComma - SlevomatCodingStandard.Attributes.AttributeAndTargetSpacing @@ -119,6 +119,7 @@ SlevomatCodingStandard (48 sniffs) - SlevomatCodingStandard.Functions.DisallowTrailingCommaInCall - SlevomatCodingStandard.Functions.DisallowTrailingCommaInClosureUse - SlevomatCodingStandard.Functions.DisallowTrailingCommaInDeclaration +- SlevomatCodingStandard.Functions.NamedArgumentSpacing - SlevomatCodingStandard.Functions.RequireTrailingCommaInCall - SlevomatCodingStandard.Functions.RequireTrailingCommaInClosureUse - SlevomatCodingStandard.Functions.RequireTrailingCommaInDeclaration From 3c23ac86aa4432d14a4eb0a6ecdb7860d162c82a Mon Sep 17 00:00:00 2001 From: ADmad Date: Sat, 30 Nov 2024 23:00:15 +0530 Subject: [PATCH 6/6] Use phive to install and run phpstan --- .gitattributes | 4 +++- .github/workflows/ci.yml | 7 +++++-- .phive/phars.xml | 4 ++++ composer.json | 3 +-- phpstan.neon | 2 +- 5 files changed, 14 insertions(+), 6 deletions(-) create mode 100644 .phive/phars.xml diff --git a/.gitattributes b/.gitattributes index 59e7ce9..33d633c 100644 --- a/.gitattributes +++ b/.gitattributes @@ -11,9 +11,11 @@ # Ignore files for distribution archives, generated using `git archive` .editorconfig export-ignore -.git export-ignore +.github export-ignore .gitattributes export-ignore .gitignore export-ignore phpcs.xml export-ignore phpunit.xml.dist export-ignore /CakePHP/Tests export-ignore +phpstan.neon export-ignore +.phive export-ignore diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index dd060c2..c099c7a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -49,14 +49,17 @@ jobs: uses: shivammathur/setup-php@v2 with: php-version: '8.1' - tools: cs2pr + tools: phive, cs2pr coverage: none - name: Composer install uses: ramsey/composer-install@v3 + - name: Install PHP tools with phive. + run: "phive install --trust-gpg-keys 'CF1A108D0E7AE720,51C67305FFC2E5C0,12CE0F1D262429A5'" + - name: Run PHP CodeSniffer run: vendor/bin/phpcs --report=checkstyle | cs2pr - name: Run PHPStan - run: vendor/bin/phpstan + run: tools/phpstan analyse --error-format=github diff --git a/.phive/phars.xml b/.phive/phars.xml new file mode 100644 index 0000000..65df421 --- /dev/null +++ b/.phive/phars.xml @@ -0,0 +1,4 @@ + + + + diff --git a/composer.json b/composer.json index 78145a8..fa3dace 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,6 @@ "squizlabs/php_codesniffer": "^3.9" }, "require-dev": { - "phpstan/phpstan": "^2.0.3", "phpunit/phpunit": "^9.3.4" }, "autoload": { @@ -46,7 +45,7 @@ ], "cs-check": "phpcs --colors --parallel=16 -p -s CakePHP/", "cs-fix": "phpcbf --colors --parallel=16 -p CakePHP/", - "stan": "phpstan analyse", + "stan": "tools/phpstan analyse", "docs": "php docs/generate.php", "explain": "phpcs -e --standard=CakePHP" } diff --git a/phpstan.neon b/phpstan.neon index bf0b10f..dfd111e 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -3,6 +3,6 @@ parameters: paths: - CakePHP/Sniffs/ bootstrapFiles: - - %rootDir%/../../../tests/phpstan_bootstrap.php + - tests/phpstan_bootstrap.php ignoreErrors: - identifier: missingType.iterableValue