Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 7 additions & 16 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand All @@ -46,7 +45,6 @@
"sort-packages": true,
"platform-check": false,
"allow-plugins": {
"cweagans/composer-patches": true,
"phpstan/extension-installer": true
}
},
Expand All @@ -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"
]
}
}
}
28 changes: 0 additions & 28 deletions patches/symfony-console-helper-helper-php.patch

This file was deleted.

1 change: 1 addition & 0 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
earlyReturn: true,
codingStyle: true,
instanceOf: true,
phpunitCodeQuality: true,
naming: true
)
->withImportNames()
Expand Down
17 changes: 11 additions & 6 deletions src/Analyzer/ClassMethodContextDefinitionsAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}

Expand All @@ -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;
}

Expand Down
16 changes: 6 additions & 10 deletions src/Command/DuplicatedDefinitionsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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: <fg=green>"' . $classMethodContextDefinition->getMask() . '"</>');
$this->symfonyStyle->writeln('Mask: <fg=green>"' . $classAndMethod->getMask() . '"</>');
$this->symfonyStyle->newLine();
}

Expand Down
14 changes: 8 additions & 6 deletions src/DefinitionMasksResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
) {
}

Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/PhpParser/SimplePhpParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use PhpParser\ParserFactory;
use Webmozart\Assert\Assert;

final class SimplePhpParser
final readonly class SimplePhpParser
{
private Parser $phpParser;

Expand Down