Skip to content
Closed
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
9 changes: 4 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@
],
"require": {
"php": ">=8.3",
"entropy/entropy": "^0.2.2",
"entropy/entropy": "^0.4",
"nette/robot-loader": "^4.1",
"nette/utils": "^4.1",
"nikic/php-parser": "^5.7",
"symfony/console": "^6.4.24",
"symfony/finder": "^7.4|^8.0",
"symfony/yaml": "^7.4|^8.0",
"webmozart/assert": "^2.4"
Expand All @@ -25,9 +24,9 @@
"shipmonk/composer-dependency-analyser": "^1.8",
"symfony/config": "^6.4",
"symfony/dependency-injection": "^6.4",
"symplify/easy-coding-standard": "^13.1",
"symplify/phpstan-extensions": "^12.0",
"tomasvotruba/class-leak": "^2.1|^3.0",
"symplify/easy-coding-standard": "^13.2",
"symplify/phpstan-rules": "^14.11",
"tomasvotruba/class-leak": "^2.1",
"tomasvotruba/unused-public": "^2.2",
"tracy/tracy": "^2.12"
},
Expand Down
5 changes: 5 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ parameters:
treatPhpDocTypesAsCertain: false
errorFormat: symplify

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

excludePaths:
- */Fixture/*
- */Source/*
Expand Down
12 changes: 6 additions & 6 deletions src/Command/AliceYamlFixturesToPhpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

use Entropy\Console\Contract\CommandInterface;
use Entropy\Console\Enum\ExitCode;
use Entropy\Console\Output\OutputPrinter;
use Nette\Utils\FileSystem;
use PhpParser\BuilderHelpers;
use PhpParser\Node\Stmt\Return_;
use PhpParser\PrettyPrinter\Standard;
use Rector\SwissKnife\Finder\FilesFinder;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Yaml\Yaml;

/**
Expand All @@ -20,7 +20,7 @@
final readonly class AliceYamlFixturesToPhpCommand implements CommandInterface
{
public function __construct(
private SymfonyStyle $symfonyStyle,
private OutputPrinter $outputPrinter,
) {
}

Expand Down Expand Up @@ -53,12 +53,12 @@ public function run(array $sources): int
// remove YAML file
unlink($yamlFileInfo->getRealPath());

$this->symfonyStyle->writeln('[DELETED] ' . $yamlFileInfo->getRelativePathname());
$this->symfonyStyle->writeln('[ADDED] ' . $phpFilePath);
$this->symfonyStyle->newLine();
$this->outputPrinter->writeln('[DELETED] ' . $yamlFileInfo->getRelativePathname());
$this->outputPrinter->writeln('[ADDED] ' . $phpFilePath);
$this->outputPrinter->newline();
}

$this->symfonyStyle->success(
$this->outputPrinter->success(
sprintf('Successfully converted %d Alice YAML fixtures to PHP', count($yamlFileInfos))
);

Expand Down
12 changes: 6 additions & 6 deletions src/Command/CheckCommentedCodeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@

use Entropy\Console\Contract\CommandInterface;
use Entropy\Console\Enum\ExitCode;
use Entropy\Console\Output\OutputPrinter;
use Rector\SwissKnife\Comments\CommentedCodeAnalyzer;
use Rector\SwissKnife\Finder\PhpFilesFinder;
use Symfony\Component\Console\Style\SymfonyStyle;

final readonly class CheckCommentedCodeCommand implements CommandInterface
{
private const int DEFAULT_LINE_LIMIT = 5;

public function __construct(
private CommentedCodeAnalyzer $commentedCodeAnalyzer,
private SymfonyStyle $symfonyStyle,
private OutputPrinter $outputPrinter,
) {
}

Expand All @@ -32,7 +32,7 @@ public function run(array $sources, array $skipFiles = [], int $lineLimit = self
$phpFileInfos = PhpFilesFinder::find($sources, $skipFiles);

$message = sprintf('Analysing %d *.php files', count($phpFileInfos));
$this->symfonyStyle->note($message);
$this->outputPrinter->writeln($message);

$commentedLinesByFilePaths = [];
foreach ($phpFileInfos as $phpFileInfo) {
Expand All @@ -46,18 +46,18 @@ public function run(array $sources, array $skipFiles = [], int $lineLimit = self
}

if ($commentedLinesByFilePaths === []) {
$this->symfonyStyle->success('No commented code found');
$this->outputPrinter->success('No commented code found');
return ExitCode::SUCCESS;
}

foreach ($commentedLinesByFilePaths as $filePath => $commentedLines) {
foreach ($commentedLines as $commentedLine) {
$messageLine = ' * ' . $filePath . ':' . $commentedLine;
$this->symfonyStyle->writeln($messageLine);
$this->outputPrinter->writeln($messageLine);
}
}

$this->symfonyStyle->error('Errors found');
$this->outputPrinter->error('Errors found');

return ExitCode::ERROR;
}
Expand Down
8 changes: 4 additions & 4 deletions src/Command/CheckConflictsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@

use Entropy\Console\Contract\CommandInterface;
use Entropy\Console\Enum\ExitCode;
use Entropy\Console\Output\OutputPrinter;
use Rector\SwissKnife\Finder\FilesFinder;
use Rector\SwissKnife\Git\ConflictResolver;
use Symfony\Component\Console\Style\SymfonyStyle;

final readonly class CheckConflictsCommand implements CommandInterface
{
public function __construct(
private ConflictResolver $conflictResolver,
private SymfonyStyle $symfonyStyle,
private OutputPrinter $outputPrinter,
) {
}

Expand All @@ -35,14 +35,14 @@ public function run(array $sources, array $exclude = []): int
$conflictsCountByFilePath = $this->conflictResolver->extractFromFileInfos($filePaths);
if ($conflictsCountByFilePath === []) {
$message = sprintf('No conflicts found in %d files', count($fileInfos));
$this->symfonyStyle->success($message);
$this->outputPrinter->success($message);

return ExitCode::SUCCESS;
}

foreach ($conflictsCountByFilePath as $file => $conflictCount) {
$message = sprintf('File "%s" contains %d unresolved conflicts', $file, $conflictCount);
$this->symfonyStyle->error($message);
$this->outputPrinter->error($message);
}

return ExitCode::ERROR;
Expand Down
8 changes: 4 additions & 4 deletions src/Command/DumpEditorconfigCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

use Entropy\Console\Contract\CommandInterface;
use Entropy\Console\Enum\ExitCode;
use Entropy\Console\Output\OutputPrinter;
use Nette\Utils\FileSystem;
use Symfony\Component\Console\Style\SymfonyStyle;

final readonly class DumpEditorconfigCommand implements CommandInterface
{
public function __construct(
private SymfonyStyle $symfonyStyle,
private OutputPrinter $outputPrinter,
) {
}

Expand All @@ -30,14 +30,14 @@ public function run(): int
{
$projectEditorconfigFilePath = getcwd() . '/.editorconfig';
if (file_exists($projectEditorconfigFilePath)) {
$this->symfonyStyle->error('.editorconfig file already exists');
$this->outputPrinter->error('.editorconfig file already exists');

return ExitCode::ERROR;
}

FileSystem::copy(__DIR__ . '/../../templates/.editorconfig', $projectEditorconfigFilePath);

$this->symfonyStyle->success('.editorconfig file was created');
$this->outputPrinter->success('.editorconfig file was created');

return ExitCode::SUCCESS;
}
Expand Down
30 changes: 16 additions & 14 deletions src/Command/FinalizeClassesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

use Entropy\Console\Contract\CommandInterface;
use Entropy\Console\Enum\ExitCode;
use Entropy\Console\Output\OutputPrinter;
use Entropy\Console\Output\ProgressBar;
use Nette\Utils\FileSystem;
use Nette\Utils\Strings;
use Rector\SwissKnife\Analyzer\NeedsFinalizeAnalyzer;
Expand All @@ -15,7 +17,6 @@
use Rector\SwissKnife\MockedClassResolver;
use Rector\SwissKnife\ParentClassResolver;
use Rector\SwissKnife\PhpParser\CachedPhpParser;
use Symfony\Component\Console\Style\SymfonyStyle;

final readonly class FinalizeClassesCommand implements CommandInterface
{
Expand All @@ -25,7 +26,8 @@
private const string NEWLINE_CLASS_START_REGEX = '#^(readonly )?class\s#m';

public function __construct(
private SymfonyStyle $symfonyStyle,
private OutputPrinter $outputPrinter,
private ProgressBar $progressBar,
private ParentClassResolver $parentClassResolver,
private EntityClassResolver $entityClassResolver,
private CachedPhpParser $cachedPhpParser,
Expand All @@ -47,23 +49,23 @@ public function run(
array $skipFiles = [],
bool $noProgress = false
): int {
$this->symfonyStyle->title('1. Detecting parent and entity classes');
$this->outputPrinter->title('1. Detecting parent and entity classes');

$phpFileInfos = PhpFilesFinder::find($paths, $skipFiles);

if (! $noProgress) {
// double to count for both parent and entity resolver
$stepRatio = $skipMocked ? 3 : 2;

$this->symfonyStyle->progressStart($stepRatio * count($phpFileInfos));
$this->progressBar->start($stepRatio * count($phpFileInfos));
}

$progressClosure = function () use ($noProgress): void {
if ($noProgress) {
return;
}

$this->symfonyStyle->progressAdvance();
$this->progressBar->advance();
};

$parentClassNames = $this->parentClassResolver->resolve($phpFileInfos, $progressClosure);
Expand All @@ -72,22 +74,22 @@ public function run(
$mockedClassNames = $skipMocked ? $this->mockedClassResolver->resolve($paths, $progressClosure) : [];

if (! $noProgress) {
$this->symfonyStyle->progressFinish();
$this->progressBar->finish();
}

$this->symfonyStyle->writeln(sprintf(
$this->outputPrinter->writeln(sprintf(
'Found %d parent and %d entity classes',
count($parentClassNames),
count($entityClassNames)
));

if ($skipMocked) {
$this->symfonyStyle->writeln(sprintf('Also %d mocked classes', count($mockedClassNames)));
$this->outputPrinter->writeln(sprintf('Also %d mocked classes', count($mockedClassNames)));
}

$this->symfonyStyle->newLine(1);
$this->outputPrinter->newline(1);

$this->symfonyStyle->title('2. Finalizing safe classes');
$this->outputPrinter->title('2. Finalizing safe classes');

$excludedClasses = array_merge($parentClassNames, $entityClassNames, $mockedClassNames);
$needsFinalizeAnalyzer = new NeedsFinalizeAnalyzer($excludedClasses, $this->cachedPhpParser);
Expand All @@ -114,18 +116,18 @@ public function run(
}

if ($finalizedFilePaths === []) {
$this->symfonyStyle->success('Nothing to finalize');
$this->outputPrinter->success('Nothing to finalize');
return ExitCode::SUCCESS;
}

$this->symfonyStyle->listing($finalizedFilePaths);
$this->outputPrinter->listing($finalizedFilePaths);

$countFinalizedClasses = count($finalizedFilePaths);
$pluralClassText = $countFinalizedClasses === 1 ? 'class' : 'classes';

// to make it fail in CI
if ($dryRun) {
$this->symfonyStyle->error(sprintf(
$this->outputPrinter->error(sprintf(
'%d %s can be finalized',
$countFinalizedClasses,
$pluralClassText,
Expand All @@ -134,7 +136,7 @@ public function run(
return ExitCode::ERROR;
}

$this->symfonyStyle->success(sprintf('%d %s finalized', $countFinalizedClasses, $pluralClassText));
$this->outputPrinter->success(sprintf('%d %s finalized', $countFinalizedClasses, $pluralClassText));

return ExitCode::SUCCESS;
}
Expand Down
10 changes: 5 additions & 5 deletions src/Command/FindMultiClassesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@

use Entropy\Console\Contract\CommandInterface;
use Entropy\Console\Enum\ExitCode;
use Entropy\Console\Output\OutputPrinter;
use Rector\SwissKnife\FileSystem\PathHelper;
use Rector\SwissKnife\Finder\MultipleClassInOneFileFinder;
use Rector\SwissKnife\Finder\PhpFilesFinder;
use Symfony\Component\Console\Style\SymfonyStyle;

final readonly class FindMultiClassesCommand implements CommandInterface
{
public function __construct(
private MultipleClassInOneFileFinder $multipleClassInOneFileFinder,
private SymfonyStyle $symfonyStyle,
private OutputPrinter $outputPrinter,
) {
}

Expand All @@ -31,7 +31,7 @@ public function run(array $sources, array $excludePaths): int

$multipleClassesByFile = $this->multipleClassInOneFileFinder->findInDirectories($sources, $excludePaths);
if ($multipleClassesByFile === []) {
$this->symfonyStyle->success(sprintf('No file with 2+ classes found in %d files', count($phpFileInfos)));
$this->outputPrinter->success(sprintf('No file with 2+ classes found in %d files', count($phpFileInfos)));

return ExitCode::SUCCESS;
}
Expand All @@ -41,8 +41,8 @@ public function run(array $sources, array $excludePaths): int
$relativeFilePath = PathHelper::relativeToCwd($filePath);

$message = sprintf('File "%s" contains %d classes', $relativeFilePath, count($classes));
$this->symfonyStyle->section($message);
$this->symfonyStyle->listing($classes);
$this->outputPrinter->section($message);
$this->outputPrinter->listing($classes);
}

return ExitCode::ERROR;
Expand Down
6 changes: 3 additions & 3 deletions src/Command/GenerateSymfonyConfigBuildersCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

use Entropy\Console\Contract\CommandInterface;
use Entropy\Console\Enum\ExitCode;
use Symfony\Component\Console\Style\SymfonyStyle;
use Entropy\Console\Output\OutputPrinter;

final readonly class GenerateSymfonyConfigBuildersCommand implements CommandInterface
{
public function __construct(
private SymfonyStyle $symfonyStyle,
private OutputPrinter $outputPrinter,
) {
}

Expand All @@ -30,7 +30,7 @@ public function getDescription(): string
*/
public function run(): int
{
$this->symfonyStyle->error(
$this->outputPrinter->error(
'This command is deprecated. Symfony 5.3 config builders were deprecated in Symfony 7.4 in favor of the new PHP configuration API. See https://symfony.com/blog/new-in-symfony-7-4-better-php-configuration'
);

Expand Down
Loading
Loading