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
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@
"autoload": {
"psr-4": {
"Rector\\SwissKnife\\": "src"
},
"classmap": [
"stubs"
]
}
},
"autoload-dev": {
"psr-4": {
"Rector\\SwissKnife\\Tests\\": "tests"
}
},
"classmap": [
"stubs"
]
},
"config": {
"sort-packages": true,
Expand Down
4 changes: 2 additions & 2 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ parameters:
errorFormat: symplify

# see https://github.com/symplify/phpstan-rules
symplify:
ctor: true
symfonyReturnType: true
laravelReturnType: true
pathStrings: true
ctor: true

excludePaths:
- */Fixture/*
Expand Down Expand Up @@ -43,4 +44,3 @@ parameters:
-
identifier: public.method.unused
message: '#Public method "Rector\\SwissKnife\\(.*?)Command\:\:run\(\)" is never used#'

4 changes: 1 addition & 3 deletions src/Command/FinalizeClassesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use Entropy\Console\Contract\CommandInterface;
use Entropy\Console\Enum\ExitCode;
use Entropy\Console\Output\OutputColorizer;
use Entropy\Console\Output\OutputPrinter;
use Entropy\Console\Output\ProgressBar;
use Nette\Utils\FileSystem;
Expand All @@ -28,7 +27,6 @@

public function __construct(
private OutputPrinter $outputPrinter,
private OutputColorizer $outputColorizer,
private ParentClassResolver $parentClassResolver,
private EntityClassResolver $entityClassResolver,
private CachedPhpParser $cachedPhpParser,
Expand Down Expand Up @@ -59,7 +57,7 @@ public function run(
// double to count for both parent and entity resolver
$stepRatio = $skipMocked ? 3 : 2;

$progressBar = new ProgressBar($this->outputColorizer);
$progressBar = new ProgressBar();
$progressBar->start($stepRatio * count($phpFileInfos));
}

Expand Down
10 changes: 8 additions & 2 deletions src/Command/GenerateSymfonySmokeTestsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Rector\SwissKnife\SmokeTestgen\Templating\TemplateDecorator;
use Rector\SwissKnife\SmokeTestgen\TestTemplateResolver;
use Rector\SwissKnife\SmokeTestgen\Utils\TestPathResolver;
use RuntimeException;
use Webmozart\Assert\Assert;

final readonly class GenerateSymfonySmokeTestsCommand implements CommandInterface
Expand Down Expand Up @@ -42,10 +43,15 @@ public function run(): int
{
$this->outputPrinter->writeln('<fg=green>Resolving directory for smoke tests</>');

$smokeTestsDirectory = $this->testsDirectoryResolver->resolveSmokeUnitTestDirectory(getcwd());
$projectDirectory = getcwd();
if (! is_string($projectDirectory)) {
throw new RuntimeException('Current working directory could not be resolved.');
}

$smokeTestsDirectory = $this->testsDirectoryResolver->resolveSmokeUnitTestDirectory($projectDirectory);
$this->outputPrinter->writeln(' * ' . $smokeTestsDirectory);

$requirePackages = $this->resolveProjectRequiredPackageNames(getcwd());
$requirePackages = $this->resolveProjectRequiredPackageNames($projectDirectory);
$testByPackageSubscribers = $this->testTemplateResolver->matchProjectPackages($requirePackages);

if ($testByPackageSubscribers === []) {
Expand Down
4 changes: 1 addition & 3 deletions src/Command/PrivatizeConstantsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use Entropy\Console\Contract\CommandInterface;
use Entropy\Console\Enum\ExitCode;
use Entropy\Console\Output\OutputColorizer;
use Entropy\Console\Output\OutputPrinter;
use Entropy\Console\Output\ProgressBar;
use Nette\Utils\FileSystem;
Expand All @@ -26,7 +25,6 @@
{
public function __construct(
private OutputPrinter $outputPrinter,
private OutputColorizer $outputColorizer,
private ClassConstantFetchFinder $classConstantFetchFinder,
private ClassConstFinder $classConstFinder,
private TwigTemplateConstantExtractor $twigTemplateConstantExtractor,
Expand Down Expand Up @@ -66,7 +64,7 @@ public function run(

$this->outputPrinter->title('Finding class const fetches...');

$progressBar = new ProgressBar($this->outputColorizer);
$progressBar = new ProgressBar();
$progressBar->start(count($phpFileInfos));

$phpClassConstantFetches = $this->classConstantFetchFinder->find($phpFileInfos, $progressBar, $isDebug);
Expand Down
8 changes: 5 additions & 3 deletions src/Command/SearchRegexCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,17 @@

use Entropy\Console\Contract\CommandInterface;
use Entropy\Console\Enum\ExitCode;
use Entropy\Console\Output\OutputColorizer;
use Entropy\Console\Output\OutputPrinter;
use Entropy\Console\Output\ProgressBar;
use Nette\Utils\Strings;
use Rector\SwissKnife\Finder\PhpFilesFinder;
use RuntimeException;
use Webmozart\Assert\Assert;

final readonly class SearchRegexCommand implements CommandInterface
{
public function __construct(
private OutputPrinter $outputPrinter,
private OutputColorizer $outputColorizer,
) {
}

Expand All @@ -31,6 +30,9 @@ public function run(string $regex, ?string $projectDirectory = null): int
{
if ($projectDirectory === null) {
$projectDirectory = getcwd();
if (! is_string($projectDirectory)) {
throw new RuntimeException('Current working directory could not be resolved.');
}
}

Assert::directory($projectDirectory);
Expand All @@ -46,7 +48,7 @@ public function run(string $regex, ?string $projectDirectory = null): int
$foundCasesCount = 0;
$markedFiles = [];

$progressBar = new ProgressBar($this->outputColorizer);
$progressBar = new ProgressBar();
$progressBar->start(count($phpFileInfos));

foreach ($phpFileInfos as $phpFileInfo) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,10 @@ private function isConstantDefinedInParentClassAlso(Class_ $class, string $const
return in_array($constantName, $this->getClassConstantNames($parentClassName), true);
}
}

foreach ($class->implements as $implement) {
if (in_array($constantName, $this->getClassConstantNames($implement->toString()), true)) {
return true;
}
}

return false;
return array_any(
$class->implements,
fn ($implement): bool => in_array($constantName, $this->getClassConstantNames($implement->toString()), true)
);
}

/**
Expand Down
13 changes: 4 additions & 9 deletions src/Testing/UnitTestFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,9 @@ private function isUnitTest(string $class): bool
if (! is_a($class, 'PHPUnit\Framework\TestCase', true) && ! is_a($class, 'PHPUnit_Framework_TestCase', true)) {
return false;
}

foreach (self::NON_UNIT_TEST_CASE_CLASSES as $nonUnitTestCaseClass) {
// required special behavior
if (is_a($class, $nonUnitTestCaseClass, true)) {
return false;
}
}

return true;
return array_all(
self::NON_UNIT_TEST_CASE_CLASSES,
fn ($nonUnitTestCaseClass): bool => ! is_a($class, $nonUnitTestCaseClass, true)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Rector\SwissKnife\Tests\PhpParser\Finder\ClassConstantFetchFinder;

use Entropy\Console\Output\OutputColorizer;
use Entropy\Console\Output\ProgressBar;
use Override;
use Rector\SwissKnife\Contract\ClassConstantFetchInterface;
Expand Down Expand Up @@ -53,7 +52,7 @@ public function testParseError(): void
);

$directory = __DIR__ . '/Fixture/Error';
$progressBar = new ProgressBar(new OutputColorizer());
$progressBar = new ProgressBar();
$fileInfos = PhpFilesFinder::find([$directory]);
$this->classConstantFetchFinder->find($fileInfos, $progressBar, false);
}
Expand All @@ -63,7 +62,7 @@ public function testParseError(): void
*/
private function findInDirectory(string $directory): array
{
$progressBar = new ProgressBar(new OutputColorizer());
$progressBar = new ProgressBar();
$fileInfos = PhpFilesFinder::find([$directory]);

return $this->classConstantFetchFinder->find($fileInfos, $progressBar, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ public function test(string $filePath, array $expectedClassNames): void
$nodeTraverser = new NodeTraverser();
$nodeTraverser->addVisitor($mockedClassNameCollectingNodeVisitor);

$parser = (new ParserFactory())->createForNewestSupportedVersion();
$parser = new ParserFactory()
->createForNewestSupportedVersion();
$stmts = $parser->parse((string) file_get_contents($filePath));
$this->assertNotNull($stmts);

Expand Down
Loading