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
4 changes: 2 additions & 2 deletions bin/behastan.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

use Rector\Behastan\DependencyInjection\ContainerFactory;
use Rector\Behastan\DependencyInjection\BehastanContainerFactory;

$possibleAutoloadPaths = [
// dependency
Expand All @@ -25,7 +25,7 @@
require_once $scoperAutoloadFilepath;
}

$container = ContainerFactory::create();
$container = BehastanContainerFactory::create();
$consoleApplication = $container->make(\Entropy\Console\ConsoleApplication::class);

$exitCode = $consoleApplication->run($argv);
Expand Down
13 changes: 7 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"bin/behastan"
],
"require": {
"php": "^8.2",
"php": "^8.3",
"nette/utils": "^4.0",
"entropy/entropy": "dev-main",
"nikic/php-parser": "^5.6",
Expand All @@ -15,11 +15,12 @@
},
"require-dev": {
"phpstan/extension-installer": "^1.4",
"phpstan/phpstan": "^2.1",
"phpunit/phpunit": "^11.5",
"rector/rector": "^2.2",
"phpecs/phpecs": "^2.2",
"tomasvotruba/class-leak": "^2.0",
"phpstan/phpstan": "^2.1.34",
"phpunit/phpunit": "^12.5",
"rector/jack": "^0.5.1",
"rector/rector": "^2.3.2",
"symplify/easy-coding-standard": "^13.0",
"tomasvotruba/class-leak": "^2.1",
"tracy/tracy": "^2.10"
},
"autoload": {
Expand Down
1 change: 1 addition & 0 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
codeQuality: true,
deadCode: true,
typeDeclarations: true,
typeDeclarationDocblocks: true,
privatization: true,
earlyReturn: true,
codingStyle: true,
Expand Down
5 changes: 1 addition & 4 deletions src/Analyzer/PatternAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@

final class PatternAnalyzer
{
/**
* @var string
*/
private const PATTERN_REGEX = '#(\:[\W\w]+)#';
private const string PATTERN_REGEX = '#(\:[\W\w]+)#';

public static function isRegex(string $rawPattern): bool
{
Expand Down
15 changes: 1 addition & 14 deletions src/Analyzer/UnusedDefinitionsAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Rector\Behastan\Analyzer;

use Nette\Utils\Strings;
use Rector\Behastan\DefinitionPatternsExtractor;
use Rector\Behastan\UsedInstructionResolver;
use Rector\Behastan\ValueObject\Pattern\AbstractPattern;
use Rector\Behastan\ValueObject\Pattern\ExactPattern;
Expand All @@ -21,14 +20,10 @@
*/
final readonly class UnusedDefinitionsAnalyzer
{
/**
* @var string
*/
private const PATTERN_VALUE_REGEX = '#(\:[\W\w]+)#';
private const string PATTERN_VALUE_REGEX = '#(\:[\W\w]+)#';

public function __construct(
private UsedInstructionResolver $usedInstructionResolver,
private DefinitionPatternsExtractor $definitionPatternsExtractor,
) {
}

Expand All @@ -40,18 +35,10 @@ public function __construct(
*/
public function analyse(array $contextFiles, array $featureFiles, PatternCollection $patternCollection): array
{
Assert::allIsInstanceOf($contextFiles, SplFileInfo::class);
foreach ($contextFiles as $contextFile) {
Assert::endsWith($contextFile->getFilename(), '.php');
}

Assert::allIsInstanceOf($featureFiles, SplFileInfo::class);
foreach ($featureFiles as $featureFile) {
Assert::endsWith($featureFile->getFilename(), '.feature');
}

$patternCollection = $this->definitionPatternsExtractor->extract($contextFiles);

$featureInstructions = $this->usedInstructionResolver->resolveInstructionsFromFeatureFiles($featureFiles);

$unusedPatterns = [];
Expand Down
5 changes: 5 additions & 0 deletions src/DefinitionPatternsExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Rector\Behastan\ValueObject\Pattern\SkippedPattern;
use Rector\Behastan\ValueObject\PatternCollection;
use SplFileInfo;
use Webmozart\Assert\Assert;

#[RelatedTest(DefinitionPatternExtractorTest::class)]
final readonly class DefinitionPatternsExtractor
Expand All @@ -35,6 +36,10 @@ public function __construct(
*/
public function extract(array $contextFiles): PatternCollection
{
foreach ($contextFiles as $contextFile) {
Assert::endsWith($contextFile->getFilename(), '.php');
}

$patterns = [];

$classMethodContextDefinitions = $this->resolvePatternsFromFiles($contextFiles);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Rector\Behastan\Contract\RuleInterface;
use Rector\Behastan\RulesRegistry;

final class ContainerFactory
final class BehastanContainerFactory
{
public static function create(): Container
{
Expand Down
15 changes: 3 additions & 12 deletions src/Enum/RuleIdentifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,9 @@

final class RuleIdentifier
{
/**
* @var string
*/
public const DUPLICATED_CONTENTS = 'duplicated-contents';
public const string DUPLICATED_CONTENTS = 'duplicated-contents';

/**
* @var string
*/
public const DUPLICATED_PATTERNS = 'duplicated-patterns';
public const string DUPLICATED_PATTERNS = 'duplicated-patterns';

/**
* @var string
*/
public const UNUSED_DEFINITIONS = 'unused-definitions';
public const string UNUSED_DEFINITIONS = 'unused-definitions';
}
5 changes: 1 addition & 4 deletions src/Resolver/ClassMethodPatternResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@

final class ClassMethodPatternResolver
{
/**
* @var string
*/
private const INSTRUCTION_DOCBLOCK_REGEX = '#\@(Given|Then|When)\s+(?<instruction>.*?)\n#m';
private const string INSTRUCTION_DOCBLOCK_REGEX = '#\@(Given|Then|When)\s+(?<instruction>.*?)\n#m';

/**
* @return string[]
Expand Down
5 changes: 5 additions & 0 deletions src/UsedInstructionResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Nette\Utils\Strings;
use RuntimeException;
use Symfony\Component\Finder\SplFileInfo;
use Webmozart\Assert\Assert;

/**
* @see \Rector\Behastan\Tests\UsedInstructionResolver\UsedInstructionResolverTest
Expand All @@ -19,6 +20,10 @@ final class UsedInstructionResolver
*/
public function resolveInstructionsFromFeatureFiles(array $featureFileInfos): array
{
foreach ($featureFileInfos as $featureFileInfo) {
Assert::endsWith($featureFileInfo->getFilename(), '.feature');
}

$instructions = [];

foreach ($featureFileInfos as $featureFileInfo) {
Expand Down
6 changes: 3 additions & 3 deletions tests/AbstractTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@

use Entropy\Container\Container;
use PHPUnit\Framework\TestCase;
use Rector\Behastan\DependencyInjection\ContainerFactory;
use Rector\Behastan\DependencyInjection\BehastanContainerFactory;

abstract class AbstractTestCase extends TestCase
{
private Container $container;

protected function setUp(): void
{
$containerFactory = new ContainerFactory();
$this->container = $containerFactory->create();
$behastanContainerFactory = new BehastanContainerFactory();
$this->container = $behastanContainerFactory->create();
}

/**
Expand Down