diff --git a/composer.json b/composer.json index 9945eb8179..34140d7f35 100644 --- a/composer.json +++ b/composer.json @@ -6,21 +6,20 @@ "bin/behastan" ], "require": { - "php": ">=8.2", - "illuminate/container": "^11.41", + "php": "^8.2", + "illuminate/container": "^11.41|^12.0", "nette/utils": "^4.0", "nikic/php-parser": "^5.4", - "symfony/console": "^6.4", - "symfony/finder": "^6.4", + "symfony/console": "^6.4|^7.0|^8.0", + "symfony/finder": "^6.4|^7.0|^8.0", "webmozart/assert": "^1.11" }, "require-dev": { "phpstan/extension-installer": "^1.4", - "phpstan/phpstan": "^2.0", + "phpstan/phpstan": "^2.1", "phpunit/phpunit": "^11.5", - "rector/rector": "^2.0", - "phpecs/phpecs": "^2.0", - "symplify/vendor-patches": "^11.3", + "rector/rector": "^2.2", + "phpecs/phpecs": "^2.2", "tomasvotruba/class-leak": "^2.0", "tracy/tracy": "^2.10" }, @@ -46,7 +45,6 @@ "sort-packages": true, "platform-check": false, "allow-plugins": { - "cweagans/composer-patches": true, "phpstan/extension-installer": true } }, @@ -55,12 +53,5 @@ "fix-cs": "vendor/bin/ecs check --fix --ansi", "phpstan": "vendor/bin/phpstan analyse --ansi", "rector": "vendor/bin/rector process --ansi" - }, - "extra": { - "patches": { - "symfony/console": [ - "patches/symfony-console-helper-helper-php.patch" - ] - } } } diff --git a/patches/symfony-console-helper-helper-php.patch b/patches/symfony-console-helper-helper-php.patch deleted file mode 100644 index 664acc1c19..0000000000 --- a/patches/symfony-console-helper-helper-php.patch +++ /dev/null @@ -1,28 +0,0 @@ ---- /dev/null -+++ ../Helper/Helper.php -@@ -47,9 +47,9 @@ - { - $string ??= ''; - -- if (preg_match('//u', $string)) { -- return (new UnicodeString($string))->width(false); -- } -+// if (preg_match('//u', $string)) { -+// return (new UnicodeString($string))->width(false); -+// } - - if (false === $encoding = mb_detect_encoding($string, null, true)) { - return \strlen($string); -@@ -66,9 +66,9 @@ - { - $string ??= ''; - -- if (preg_match('//u', $string)) { -- return (new UnicodeString($string))->length(); -- } -+// if (preg_match('//u', $string)) { -+// return (new UnicodeString($string))->length(); -+// } - - if (false === $encoding = mb_detect_encoding($string, null, true)) { - return \strlen($string); diff --git a/rector.php b/rector.php index 37dfe99c8b..0489ab6d2c 100644 --- a/rector.php +++ b/rector.php @@ -15,6 +15,7 @@ earlyReturn: true, codingStyle: true, instanceOf: true, + phpunitCodeQuality: true, naming: true ) ->withImportNames() diff --git a/src/Analyzer/ClassMethodContextDefinitionsAnalyzer.php b/src/Analyzer/ClassMethodContextDefinitionsAnalyzer.php index a112445275..dfe7c0b4a3 100644 --- a/src/Analyzer/ClassMethodContextDefinitionsAnalyzer.php +++ b/src/Analyzer/ClassMethodContextDefinitionsAnalyzer.php @@ -33,10 +33,10 @@ public function resolve(array $contextFileInfos): array $classMethodContextDefinitionByClassMethodHash = $this->resolveAndGroupByContentHash($contextFileInfos); $classMethodContextDefinitions = []; - foreach ($classMethodContextDefinitionByClassMethodHash as $currentClassMethodContextDefinitions) { + foreach ($classMethodContextDefinitionByClassMethodHash as $classMethodContextDefinition) { $classMethodContextDefinitions = array_merge( $classMethodContextDefinitions, - $currentClassMethodContextDefinitions + $classMethodContextDefinition ); } @@ -55,23 +55,28 @@ public function resolveAndGroupByContentHash(array $contextFileInfos): array $contextClassStmts = $this->simplePhpParser->parseFilePath($contextFileInfo->getRealPath()); $class = $this->nodeFinder->findFirstInstanceOf($contextClassStmts, Class_::class); - if (! $class instanceof Class_ || ! $class->namespacedName instanceof Name) { + if (! $class instanceof Class_) { + continue; + } + if (! $class->namespacedName instanceof Name) { continue; } $className = $class->namespacedName->toString(); foreach ($class->getMethods() as $classMethod) { - if (! $classMethod->isPublic() || $classMethod->isMagic()) { + if (! $classMethod->isPublic()) { + continue; + } + if ($classMethod->isMagic()) { continue; } - $classMethodHash = $this->createClassMethodHash($classMethod); $rawMasks = $this->classMethodMasksResolver->resolve($classMethod); // no masks :( - if (count($rawMasks) === 0) { + if ($rawMasks === []) { continue; } diff --git a/src/Command/DuplicatedDefinitionsCommand.php b/src/Command/DuplicatedDefinitionsCommand.php index a9b75bec85..c4fb945134 100644 --- a/src/Command/DuplicatedDefinitionsCommand.php +++ b/src/Command/DuplicatedDefinitionsCommand.php @@ -7,7 +7,6 @@ use Behastan\Analyzer\ClassMethodContextDefinitionsAnalyzer; use Behastan\Enum\Option; use Behastan\Finder\BehatMetafilesFinder; -use Behastan\ValueObject\ClassMethodContextDefinition; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; @@ -60,21 +59,18 @@ protected function execute(InputInterface $input, OutputInterface $output): int ); $i = 0; - foreach ($classMethodContextDefinitionByClassMethodHash as $classAndMethods) { + foreach ($classMethodContextDefinitionByClassMethodHash as $classMethodContextDefinition) { $this->symfonyStyle->section(sprintf('%d)', $i + 1)); - foreach ($classAndMethods as $classMethodContextDefinition) { - /** @var ClassMethodContextDefinition $classMethodContextDefinition */ + foreach ($classMethodContextDefinition as $classAndMethod) { $relativeFilePath = substr( - $classMethodContextDefinition->getFilePath(), - strlen($testDirectories[0]) + 1 + $classAndMethod->getFilePath(), + strlen((string) $testDirectories[0]) + 1 ); - $this->symfonyStyle->writeln( - $relativeFilePath . ':' . $classMethodContextDefinition->getMethodLine() - ); + $this->symfonyStyle->writeln($relativeFilePath . ':' . $classAndMethod->getMethodLine()); - $this->symfonyStyle->writeln('Mask: "' . $classMethodContextDefinition->getMask() . '"'); + $this->symfonyStyle->writeln('Mask: "' . $classAndMethod->getMask() . '"'); $this->symfonyStyle->newLine(); } diff --git a/src/DefinitionMasksResolver.php b/src/DefinitionMasksResolver.php index 5bab11cc6c..63da8e64cb 100644 --- a/src/DefinitionMasksResolver.php +++ b/src/DefinitionMasksResolver.php @@ -18,12 +18,12 @@ use PhpParser\NodeFinder; use SplFileInfo; -final class DefinitionMasksResolver +final readonly class DefinitionMasksResolver { public function __construct( - private readonly SimplePhpParser $simplePhpParser, - private readonly NodeFinder $nodeFinder, - private readonly ClassMethodMasksResolver $classMethodMasksResolver, + private SimplePhpParser $simplePhpParser, + private NodeFinder $nodeFinder, + private ClassMethodMasksResolver $classMethodMasksResolver, ) { } @@ -100,9 +100,11 @@ private function resolveMasksFromFiles(array $fileInfos): array if (! $class instanceof Class_) { continue; } - // is magic class? - if ($class->isAnonymous() || ! $class->namespacedName instanceof Name) { + if ($class->isAnonymous()) { + continue; + } + if (! $class->namespacedName instanceof Name) { continue; } diff --git a/src/PhpParser/SimplePhpParser.php b/src/PhpParser/SimplePhpParser.php index c73612ba38..024c2e1587 100644 --- a/src/PhpParser/SimplePhpParser.php +++ b/src/PhpParser/SimplePhpParser.php @@ -11,7 +11,7 @@ use PhpParser\ParserFactory; use Webmozart\Assert\Assert; -final class SimplePhpParser +final readonly class SimplePhpParser { private Parser $phpParser;