From ce9f36bcdb35e1439685ac6aab590c29dd952331 Mon Sep 17 00:00:00 2001 From: Simtel Date: Mon, 11 Aug 2025 10:05:53 +0400 Subject: [PATCH 1/2] .gitattributes added --- .gitattributes | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..76e84a3 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,6 @@ +/.github export-ignore +/tests export-ignore +/.gitattributes export-ignore +/.gitignore export-ignore +/phpstan.neon export-ignore +/phpunit.xml.dist export-ignore \ No newline at end of file From c84954353c35317d4a77cb4a92179c063004dcf5 Mon Sep 17 00:00:00 2001 From: Simtel Date: Mon, 11 Aug 2025 10:12:44 +0400 Subject: [PATCH 2/2] .gitattributes added --- .gitattributes | 3 +- composer.json | 3 +- composer.lock | 63 ++++++++++++++++++- ...ndClassShouldBeHelpCommandHandlerClass.php | 6 +- ...lassShouldBeIncludeAsListenerAttribute.php | 13 ++-- .../NotShouldPhpdocReturnIfExistTypeHint.php | 17 +++-- .../Fixture/EventListener/AsEventListener.php | 6 +- .../EventListener/TestClassEventListener.php | 6 +- ...assShouldBeHelpCommandHandlerClassTest.php | 15 ++--- ...ShouldBeIncludeAsListenerAttributeTest.php | 7 +-- ...tShouldPhpdocReturnIfExistTypeHintTest.php | 11 +--- tests/data/command_handler_data1.php | 1 - tests/data/command_handler_data2.php | 1 - tests/data/command_handler_data3.php | 1 - 14 files changed, 94 insertions(+), 59 deletions(-) diff --git a/.gitattributes b/.gitattributes index 76e84a3..a10eb83 100644 --- a/.gitattributes +++ b/.gitattributes @@ -3,4 +3,5 @@ /.gitattributes export-ignore /.gitignore export-ignore /phpstan.neon export-ignore -/phpunit.xml.dist export-ignore \ No newline at end of file +/phpunit.xml.dist export-ignore +/ecs.php export-ignore \ No newline at end of file diff --git a/composer.json b/composer.json index a649e6c..3e528ac 100644 --- a/composer.json +++ b/composer.json @@ -20,6 +20,7 @@ } }, "require-dev": { - "phpunit/phpunit": "^12.0" + "phpunit/phpunit": "^12.0", + "symplify/easy-coding-standard": "^12.5" } } diff --git a/composer.lock b/composer.lock index d52081d..4bf037b 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "b8a3cce49651ba22542fba4c31e0631c", + "content-hash": "0a8b322c08d6cae502ebc557da5b099f", "packages": [ { "name": "phpstan/phpdoc-parser", @@ -1677,6 +1677,67 @@ ], "time": "2024-10-20T05:08:20+00:00" }, + { + "name": "symplify/easy-coding-standard", + "version": "12.5.22", + "source": { + "type": "git", + "url": "https://github.com/easy-coding-standard/easy-coding-standard.git", + "reference": "4581ec472a86ff11f2f3909a4dd14a9e6fa2110b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/easy-coding-standard/easy-coding-standard/zipball/4581ec472a86ff11f2f3909a4dd14a9e6fa2110b", + "reference": "4581ec472a86ff11f2f3909a4dd14a9e6fa2110b", + "shasum": "" + }, + "require": { + "php": ">=7.2" + }, + "conflict": { + "friendsofphp/php-cs-fixer": "<3.46", + "phpcsstandards/php_codesniffer": "<3.8", + "symplify/coding-standard": "<12.1" + }, + "suggest": { + "ext-dom": "Needed to support checkstyle output format in class CheckstyleOutputFormatter" + }, + "bin": [ + "bin/ecs" + ], + "type": "library", + "autoload": { + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Use Coding Standard with 0-knowledge of PHP-CS-Fixer and PHP_CodeSniffer", + "keywords": [ + "Code style", + "automation", + "fixer", + "static analysis" + ], + "support": { + "issues": "https://github.com/easy-coding-standard/easy-coding-standard/issues", + "source": "https://github.com/easy-coding-standard/easy-coding-standard/tree/12.5.22" + }, + "funding": [ + { + "url": "https://www.paypal.me/rectorphp", + "type": "custom" + }, + { + "url": "https://github.com/tomasvotruba", + "type": "github" + } + ], + "time": "2025-07-31T06:08:02+00:00" + }, { "name": "theseer/tokenizer", "version": "1.2.3", diff --git a/src/Rule/CommandClassShouldBeHelpCommandHandlerClass.php b/src/Rule/CommandClassShouldBeHelpCommandHandlerClass.php index 8dcf27b..374a57f 100644 --- a/src/Rule/CommandClassShouldBeHelpCommandHandlerClass.php +++ b/src/Rule/CommandClassShouldBeHelpCommandHandlerClass.php @@ -19,7 +19,6 @@ */ final class CommandClassShouldBeHelpCommandHandlerClass implements Rule { - public function __construct( private readonly PhpDocParser $parser, private readonly Lexer $phpDocLexer, @@ -44,7 +43,7 @@ public function processNode(Node $node, Scope $scope): array $className = $node->name->name; } - if (!str_ends_with($className, 'Command')) { + if (! str_ends_with($className, 'Command')) { return []; } @@ -70,7 +69,7 @@ public function processNode(Node $node, Scope $scope): array if ($tag->value instanceof GenericTagValueNode) { $find = true; $value = $tag->value->value; - if (!str_ends_with($value, 'CommandHandler')) { + if (! str_ends_with($value, 'CommandHandler')) { return [ RuleErrorBuilder::message( sprintf( @@ -92,5 +91,4 @@ public function processNode(Node $node, Scope $scope): array return []; } - } diff --git a/src/Rule/EventListenerClassShouldBeIncludeAsListenerAttribute.php b/src/Rule/EventListenerClassShouldBeIncludeAsListenerAttribute.php index 3e2276d..d949fde 100644 --- a/src/Rule/EventListenerClassShouldBeIncludeAsListenerAttribute.php +++ b/src/Rule/EventListenerClassShouldBeIncludeAsListenerAttribute.php @@ -16,9 +16,9 @@ */ final class EventListenerClassShouldBeIncludeAsListenerAttribute implements Rule { - - public function __construct(private readonly ReflectionProvider $reflectionProvider) - { + public function __construct( + private readonly ReflectionProvider $reflectionProvider + ) { } public function getNodeType(): string @@ -39,7 +39,7 @@ public function processNode(Node $node, Scope $scope): array $className = $node->name->name; } - if (!str_ends_with($className, 'EventListener')) { + if (! str_ends_with($className, 'EventListener')) { return []; } @@ -61,8 +61,9 @@ public function processNode(Node $node, Scope $scope): array if ($find === false) { return [ - RuleErrorBuilder::message('Event listener class should be include attribute #[AsEventListener]')->build( - ), + RuleErrorBuilder::message( + 'Event listener class should be include attribute #[AsEventListener]' + )->build(), ]; } diff --git a/src/Rule/NotShouldPhpdocReturnIfExistTypeHint.php b/src/Rule/NotShouldPhpdocReturnIfExistTypeHint.php index 4ab1eee..eae2bfc 100644 --- a/src/Rule/NotShouldPhpdocReturnIfExistTypeHint.php +++ b/src/Rule/NotShouldPhpdocReturnIfExistTypeHint.php @@ -13,14 +13,12 @@ use PHPStan\PhpDocParser\Parser\TokenIterator; use PHPStan\Reflection\ReflectionProvider; use PHPStan\Rules\Rule; -use PHPStan\ShouldNotHappenException; /** * @implements Rule */ final class NotShouldPhpdocReturnIfExistTypeHint implements Rule { - public function __construct( private readonly ReflectionProvider $reflectionProvider, private readonly PhpDocParser $parser, @@ -33,9 +31,6 @@ public function getNodeType(): string return Class_::class; } - /** - * @throws ShouldNotHappenException - */ public function processNode(Node $node, Scope $scope): array { $fullyQualifiedClassName = $node->namespacedName?->toString(); @@ -54,14 +49,13 @@ public function processNode(Node $node, Scope $scope): array continue; } - $doc = (string)$method->getDocComment(); + $doc = (string) $method->getDocComment(); if ($doc === '') { continue; } - $returnType = $method->getReturnType(); - if ($returnType === null || !method_exists($returnType, 'getName')) { + if ($returnType === null || ! method_exists($returnType, 'getName')) { return []; } @@ -76,10 +70,13 @@ public function processNode(Node $node, Scope $scope): array if ($tag->value instanceof ReturnTagValueNode) { $value = $tag->value->type->name; if ($value === $returnTypeName - && $reflection->getName() === $method->getBetterReflection()->getLocatedSource()->getName()) { + && $reflection->getName() === $method->getBetterReflection() + ->getLocatedSource() + ->getName()) { $errors[] = \PHPStan\Rules\RuleErrorBuilder::message( 'PhpDoc attribute @return for method ' . $method->getName() . ' can be remove' - )->line((int)$method->getStartLine())->build(); + )->line((int) $method->getStartLine()) + ->build(); } } } diff --git a/tests/Fixture/EventListener/AsEventListener.php b/tests/Fixture/EventListener/AsEventListener.php index f4d286e..92df92d 100644 --- a/tests/Fixture/EventListener/AsEventListener.php +++ b/tests/Fixture/EventListener/AsEventListener.php @@ -9,7 +9,7 @@ #[Attribute] class AsEventListener { - public function __construct( - ) - {} + public function __construct() + { + } } diff --git a/tests/Fixture/EventListener/TestClassEventListener.php b/tests/Fixture/EventListener/TestClassEventListener.php index ccae27a..7ac8e6b 100644 --- a/tests/Fixture/EventListener/TestClassEventListener.php +++ b/tests/Fixture/EventListener/TestClassEventListener.php @@ -1,15 +1,13 @@ analyse([__DIR__ . '/../data/command_handler_data2.php'], [ - [ - 'PhpDoc command class should be include @see attribute with CommandHandler class name', - 10 - ] + ['PhpDoc command class should be include @see attribute with CommandHandler class name', 10] ]); } public function testExistsPhpDoc(): void { $this->analyse([__DIR__ . '/../data/command_handler_data3.php'], [ - [ - 'Command class should be include phpDoc with @see attribute', - 7 - ] + ['Command class should be include phpDoc with @see attribute', 7] ]); } diff --git a/tests/Rules/EventListenerClassShouldBeIncludeAsListenerAttributeTest.php b/tests/Rules/EventListenerClassShouldBeIncludeAsListenerAttributeTest.php index d174d14..694319f 100644 --- a/tests/Rules/EventListenerClassShouldBeIncludeAsListenerAttributeTest.php +++ b/tests/Rules/EventListenerClassShouldBeIncludeAsListenerAttributeTest.php @@ -10,7 +10,6 @@ class EventListenerClassShouldBeIncludeAsListenerAttributeTest extends RuleTestCase { - /** * @inheritDoc */ @@ -27,11 +26,7 @@ public function testExistsNeedAttribute(): void public function testExistsAttribute(): void { $this->analyse([__DIR__ . '/../Fixture/EventListener/TestNotCorrectClassEventListener.php'], [ - [ - 'Event listener class should be include attribute #[AsEventListener]', - 7 - ] + ['Event listener class should be include attribute #[AsEventListener]', 7] ]); } - } diff --git a/tests/Rules/NotShouldPhpdocReturnIfExistTypeHintTest.php b/tests/Rules/NotShouldPhpdocReturnIfExistTypeHintTest.php index ef7226a..6f80407 100644 --- a/tests/Rules/NotShouldPhpdocReturnIfExistTypeHintTest.php +++ b/tests/Rules/NotShouldPhpdocReturnIfExistTypeHintTest.php @@ -15,7 +15,6 @@ class NotShouldPhpdocReturnIfExistTypeHintTest extends RuleTestCase { - /** * @inheritDoc */ @@ -33,14 +32,8 @@ public function getRule(): Rule public function testWithError(): void { $this->analyse([__DIR__ . '/../Fixture/Return/MethodsWithTypeHintAndReturn.php'], [ - [ - 'PhpDoc attribute @return for method someMethod can be remove', - 12 - ], - [ - 'PhpDoc attribute @return for method getInt can be remove', - 20 - ], + ['PhpDoc attribute @return for method someMethod can be remove', 12], + ['PhpDoc attribute @return for method getInt can be remove', 20], ]); } } diff --git a/tests/data/command_handler_data1.php b/tests/data/command_handler_data1.php index 552479d..00eb59e 100644 --- a/tests/data/command_handler_data1.php +++ b/tests/data/command_handler_data1.php @@ -9,5 +9,4 @@ */ class TestClassCommand { - } diff --git a/tests/data/command_handler_data2.php b/tests/data/command_handler_data2.php index eb685d5..30421a5 100644 --- a/tests/data/command_handler_data2.php +++ b/tests/data/command_handler_data2.php @@ -9,5 +9,4 @@ */ class TestClassCommand { - } diff --git a/tests/data/command_handler_data3.php b/tests/data/command_handler_data3.php index fd30023..61e23df 100644 --- a/tests/data/command_handler_data3.php +++ b/tests/data/command_handler_data3.php @@ -6,5 +6,4 @@ class TestClassCommand { - }