Skip to content

Commit cdbafe7

Browse files
committed
Updated ECS to commit 54eb0bcb1a037c7e785044a81fc94f6c1e7d45e1
1 parent 94f56bc commit cdbafe7

227 files changed

Lines changed: 398 additions & 22786 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

bin/ecs.php

Lines changed: 61 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@
44
namespace ECSPrefix202606;
55

66
// decoupled in own "*.php" file, so ECS, Rector and PHPStan works out of the box here
7+
use ECSPrefix202606\Composer\InstalledVersions;
8+
use ECSPrefix202606\Composer\XdebugHandler\XdebugHandler;
9+
use ECSPrefix202606\Entropy\Console\ConsoleApplication;
10+
use ECSPrefix202606\Entropy\Console\Output\OutputColorizer;
11+
use ECSPrefix202606\Entropy\Console\Output\OutputPrinter;
712
use PHP_CodeSniffer\Util\Tokens;
8-
use ECSPrefix202606\Symfony\Component\Console\Command\Command;
9-
use ECSPrefix202606\Symfony\Component\Console\Input\ArgvInput;
10-
use Symplify\EasyCodingStandard\Console\EasyCodingStandardConsoleApplication;
11-
use Symplify\EasyCodingStandard\Console\Style\SymfonyStyleFactory;
13+
use Symplify\EasyCodingStandard\Application\Version\StaticVersionResolver;
14+
use Symplify\EasyCodingStandard\Console\ExitCode;
1215
use Symplify\EasyCodingStandard\DependencyInjection\EasyCodingStandardContainerFactory;
1316
use Symplify\EasyCodingStandard\DependencyInjection\ServiceContainerFactory;
1417
// performance boost
@@ -120,18 +123,62 @@ public function loadIfNotLoadedYet(string $file): void
120123
* Inspired by https://github.com/rectorphp/rector/pull/2373/files#diff-0fc04a2bb7928cac4ae339d5a8bf67f3
121124
*/
122125
\class_alias('ECSPrefix202606\ECSAutoloadIncluder', 'ECSAutoloadIncluder', \false);
126+
$rawArgv = $_SERVER['argv'] ?? [];
127+
// @fixes https://github.com/rectorphp/rector/issues/2205
128+
$isXdebugAllowed = \in_array('--xdebug', $rawArgv, \true);
129+
if (!$isXdebugAllowed && !\defined('PHPUNIT_COMPOSER_INSTALL')) {
130+
$xdebugHandler = new XdebugHandler('ecs');
131+
$xdebugHandler->check();
132+
unset($xdebugHandler);
133+
}
123134
try {
124-
$input = new ArgvInput();
125135
$ecsContainerFactory = new EasyCodingStandardContainerFactory();
126-
$container = $ecsContainerFactory->createFromFromInput($input);
136+
$container = $ecsContainerFactory->createFromArgv($rawArgv);
127137
} catch (\Throwable $throwable) {
128-
$symfonyStyleFactory = new SymfonyStyleFactory();
129-
$symfonyStyle = $symfonyStyleFactory->create();
130-
$symfonyStyle->error($throwable->getMessage());
131-
$symfonyStyle->writeln($throwable->getTraceAsString());
132-
exit(Command::FAILURE);
138+
$outputPrinter = new OutputPrinter(new OutputColorizer());
139+
$outputPrinter->error($throwable->getMessage());
140+
$outputPrinter->writeln($throwable->getTraceAsString());
141+
exit(ExitCode::FAILURE);
142+
}
143+
// print version and exit
144+
if (\in_array('--version', $rawArgv, \true) || \in_array('-V', $rawArgv, \true)) {
145+
echo \sprintf('EasyCodingStandard %s', StaticVersionResolver::PACKAGE_VERSION) . \PHP_EOL;
146+
echo \sprintf('+ PHP_CodeSniffer %s', InstalledVersions::getPrettyVersion('squizlabs/php_codesniffer')) . \PHP_EOL;
147+
echo \sprintf('+ PHP-CS-Fixer %s', InstalledVersions::getPrettyVersion('friendsofphp/php-cs-fixer')) . \PHP_EOL;
148+
exit(ExitCode::SUCCESS);
133149
}
134-
/** @var EasyCodingStandardConsoleApplication $application */
135-
$application = $container->make(EasyCodingStandardConsoleApplication::class);
136-
$statusCode = $application->run();
150+
/** @var ConsoleApplication $application */
151+
$application = $container->make(ConsoleApplication::class);
152+
$statusCode = $application->run(ecs_normalize_argv($rawArgv));
137153
exit($statusCode);
154+
/**
155+
* Strip global/decoration flags Symfony Console handled implicitly, and normalize
156+
* the "-c" config shortcut to "--config", so the Entropy input parser does not
157+
* treat them as unknown command options.
158+
*
159+
* @param string[] $argv
160+
* @return string[]
161+
*/
162+
function ecs_normalize_argv(array $argv): array
163+
{
164+
$decorationFlags = ['--ansi', '--no-ansi', '--quiet', '-q', '--no-interaction', '-n', '-v', '-vv', '-vvv', '--xdebug'];
165+
if (\in_array('--no-ansi', $argv, \true)) {
166+
\putenv('NO_COLOR=1');
167+
}
168+
$normalized = [];
169+
foreach ($argv as $arg) {
170+
if (\in_array($arg, $decorationFlags, \true)) {
171+
continue;
172+
}
173+
if ($arg === '-c') {
174+
$normalized[] = '--config';
175+
continue;
176+
}
177+
if (\strncmp($arg, '-c=', \strlen('-c=')) === 0) {
178+
$normalized[] = '--config=' . \substr($arg, 3);
179+
continue;
180+
}
181+
$normalized[] = $arg;
182+
}
183+
return $normalized;
184+
}

src/Application/EasyCodingStandardApplication.php

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
namespace Symplify\EasyCodingStandard\Application;
55

66
use ParseError;
7-
use ECSPrefix202606\Symfony\Component\Console\Input\InputInterface;
8-
use ECSPrefix202606\Symfony\Component\Console\Style\SymfonyStyle;
97
use Symplify\EasyCodingStandard\Caching\ChangedFilesDetector;
108
use Symplify\EasyCodingStandard\Console\Style\EasyCodingStandardStyle;
119
use Symplify\EasyCodingStandard\DependencyInjection\SimpleParameterProvider;
@@ -65,11 +63,6 @@ final class EasyCodingStandardApplication
6563
* @var \Symplify\EasyParallel\CpuCoreCountProvider
6664
*/
6765
private $cpuCoreCountProvider;
68-
/**
69-
* @readonly
70-
* @var \Symfony\Component\Console\Style\SymfonyStyle
71-
*/
72-
private $symfonyStyle;
7366
/**
7467
* @readonly
7568
* @var \Symplify\EasyCodingStandard\Utils\ParametersMerger
@@ -79,7 +72,7 @@ final class EasyCodingStandardApplication
7972
* @var string
8073
*/
8174
private const ARGV = 'argv';
82-
public function __construct(EasyCodingStandardStyle $easyCodingStandardStyle, SourceFinder $sourceFinder, ChangedFilesDetector $changedFilesDetector, FileFilter $fileFilter, \Symplify\EasyCodingStandard\Application\SingleFileProcessor $singleFileProcessor, ScheduleFactory $scheduleFactory, ParallelFileProcessor $parallelFileProcessor, CpuCoreCountProvider $cpuCoreCountProvider, SymfonyStyle $symfonyStyle, ParametersMerger $parametersMerger)
75+
public function __construct(EasyCodingStandardStyle $easyCodingStandardStyle, SourceFinder $sourceFinder, ChangedFilesDetector $changedFilesDetector, FileFilter $fileFilter, \Symplify\EasyCodingStandard\Application\SingleFileProcessor $singleFileProcessor, ScheduleFactory $scheduleFactory, ParallelFileProcessor $parallelFileProcessor, CpuCoreCountProvider $cpuCoreCountProvider, ParametersMerger $parametersMerger)
8376
{
8477
$this->easyCodingStandardStyle = $easyCodingStandardStyle;
8578
$this->sourceFinder = $sourceFinder;
@@ -89,13 +82,12 @@ public function __construct(EasyCodingStandardStyle $easyCodingStandardStyle, So
8982
$this->scheduleFactory = $scheduleFactory;
9083
$this->parallelFileProcessor = $parallelFileProcessor;
9184
$this->cpuCoreCountProvider = $cpuCoreCountProvider;
92-
$this->symfonyStyle = $symfonyStyle;
9385
$this->parametersMerger = $parametersMerger;
9486
}
9587
/**
9688
* @return array{coding_standard_errors?: CodingStandardError[], file_diffs?: FileDiff[], system_errors?: SystemError[]|string[], system_errors_count?: int}
9789
*/
98-
public function run(Configuration $configuration, InputInterface $input): array
90+
public function run(Configuration $configuration): array
9991
{
10092
// 1. find files in sources
10193
$filePaths = $this->sourceFinder->find($configuration->getSources());
@@ -120,18 +112,18 @@ public function run(Configuration $configuration, InputInterface $input): array
120112
}
121113
if (!$isProgressBarStarted) {
122114
$fileCount = count($filePaths);
123-
$this->symfonyStyle->progressStart($fileCount);
115+
$this->easyCodingStandardStyle->progressStart($fileCount);
124116
$isProgressBarStarted = \true;
125117
}
126-
$this->symfonyStyle->progressAdvance($stepCount);
118+
$this->easyCodingStandardStyle->progressAdvance($stepCount);
127119
// running in parallel here → nothing else to do
128120
};
129121
$mainScript = $this->resolveCalledEcsBinary();
130122
if ($mainScript === null) {
131123
throw new ShouldNotHappenException('[parallel] Main script was not found');
132124
}
133125
// mimics see https://github.com/phpstan/phpstan-src/commit/9124c66dcc55a222e21b1717ba5f60771f7dda92#diff-387b8f04e0db7a06678eb52ce0c0d0aff73e0d7d8fc5df834d0a5fbec198e5daR139
134-
return $this->parallelFileProcessor->check($schedule, $mainScript, $postFileCallback, $configuration->getConfig(), $input);
126+
return $this->parallelFileProcessor->check($schedule, $mainScript, $postFileCallback, $configuration->getConfig(), $configuration);
135127
}
136128
// process found files by each processors
137129
return $this->processFoundFiles($filePaths, $configuration);

src/Application/Version/StaticVersionResolver.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ final class StaticVersionResolver
1515
* @api
1616
* @var string
1717
*/
18-
public const PACKAGE_VERSION = '13.2.3';
18+
public const PACKAGE_VERSION = '54eb0bcb1a037c7e785044a81fc94f6c1e7d45e1';
1919
/**
2020
* @api
2121
* @var string
2222
*/
23-
public const RELEASE_DATE = '2026-06-15 21:50:29';
23+
public const RELEASE_DATE = '2026-06-20 01:01:05';
2424
/**
2525
* @var int
2626
*/

src/Configuration/ConfigInitializer.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
namespace Symplify\EasyCodingStandard\Configuration;
55

66
use ECSPrefix202606\Nette\Utils\FileSystem;
7-
use ECSPrefix202606\Symfony\Component\Console\Style\SymfonyStyle;
87
use Symplify\EasyCodingStandard\Application\FileProcessorCollector;
8+
use Symplify\EasyCodingStandard\Console\Style\EasyCodingStandardStyle;
99
final class ConfigInitializer
1010
{
1111
/**
@@ -15,9 +15,9 @@ final class ConfigInitializer
1515
private $fileProcessorCollector;
1616
/**
1717
* @readonly
18-
* @var \Symfony\Component\Console\Style\SymfonyStyle
18+
* @var \Symplify\EasyCodingStandard\Console\Style\EasyCodingStandardStyle
1919
*/
20-
private $symfonyStyle;
20+
private $easyCodingStandardStyle;
2121
/**
2222
* @readonly
2323
* @var \Symplify\EasyCodingStandard\Configuration\InitPathsResolver
@@ -28,10 +28,10 @@ final class ConfigInitializer
2828
* @var \Symfony\Component\Filesystem\Filesystem
2929
*/
3030
private $filesystem;
31-
public function __construct(FileProcessorCollector $fileProcessorCollector, SymfonyStyle $symfonyStyle, \Symplify\EasyCodingStandard\Configuration\InitPathsResolver $initPathsResolver, \ECSPrefix202606\Symfony\Component\Filesystem\Filesystem $filesystem)
31+
public function __construct(FileProcessorCollector $fileProcessorCollector, EasyCodingStandardStyle $easyCodingStandardStyle, \Symplify\EasyCodingStandard\Configuration\InitPathsResolver $initPathsResolver, \ECSPrefix202606\Symfony\Component\Filesystem\Filesystem $filesystem)
3232
{
3333
$this->fileProcessorCollector = $fileProcessorCollector;
34-
$this->symfonyStyle = $symfonyStyle;
34+
$this->easyCodingStandardStyle = $easyCodingStandardStyle;
3535
$this->initPathsResolver = $initPathsResolver;
3636
$this->filesystem = $filesystem;
3737
}
@@ -52,10 +52,10 @@ public function createConfig(string $projectDirectory): void
5252
$doesConfigExist = $this->filesystem->exists($projectDirectory . '/ecs.php');
5353
// config already exists, nothing to add
5454
if ($doesConfigExist) {
55-
$this->symfonyStyle->warning('We found ecs.php config, but no rules in it. Register some rules or sets there first');
55+
$this->easyCodingStandardStyle->warning('We found ecs.php config, but no rules in it. Register some rules or sets there first');
5656
return;
5757
}
58-
$response = $this->symfonyStyle->ask('No "ecs.php" config found. Should we generate it for you?', 'yes');
58+
$response = $this->easyCodingStandardStyle->ask('No "ecs.php" config found. Should we generate it for you?', 'yes');
5959
// be tolerant about input
6060
if (!in_array($response, ['yes', 'YES', 'y', 'Y'], \true)) {
6161
// okay, nothing we can do
@@ -66,7 +66,7 @@ public function createConfig(string $projectDirectory): void
6666
$templateFileContents = $this->fillPreparedSets($projectDirectory, $templateFileContents);
6767
// create the ecs.php file
6868
FileSystem::write(getcwd() . '/ecs.php', $templateFileContents, null);
69-
$this->symfonyStyle->success('The ecs.php config was generated! Re-run the command to tidy your code');
69+
$this->easyCodingStandardStyle->success('The ecs.php config was generated! Re-run the command to tidy your code');
7070
}
7171
private function fillPaths(string $projectDirectory, string $templateFileContents): string
7272
{

src/Configuration/ConfigurationFactory.php

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
declare (strict_types=1);
44
namespace Symplify\EasyCodingStandard\Configuration;
55

6-
use ECSPrefix202606\Symfony\Component\Console\Input\InputInterface;
76
use Symplify\EasyCodingStandard\Console\Output\OutputFormatterCollector;
87
use Symplify\EasyCodingStandard\DependencyInjection\SimpleParameterProvider;
98
use Symplify\EasyCodingStandard\Exception\Configuration\SourceNotFoundException;
@@ -22,41 +21,30 @@ public function __construct(OutputFormatterCollector $outputFormatterCollector)
2221
}
2322
/**
2423
* Needs to run in the start of the life cycle, since the rest of workflow uses it.
24+
*
25+
* @param string[] $paths
2526
*/
26-
public function createFromInput(InputInterface $input): Configuration
27+
public function create(array $paths, bool $isFixer, bool $shouldClearCache, bool $noProgressBar, bool $noErrorTable, bool $noDiffs, string $outputFormat, ?string $config, string $parallelPort, string $parallelIdentifier, ?string $memoryLimit, bool $debug): Configuration
2728
{
28-
$paths = $this->resolvePaths($input);
29-
$isFixer = (bool) $input->getOption(Option::FIX);
30-
$shouldClearCache = (bool) $input->getOption(Option::CLEAR_CACHE);
31-
$showProgressBar = $this->canShowProgressBar($input);
32-
$showErrorTable = !(bool) $input->getOption(Option::NO_ERROR_TABLE);
33-
$showDiffs = !(bool) $input->getOption(Option::NO_DIFFS);
34-
$parallelPort = (string) $input->getOption(Option::PARALLEL_PORT);
35-
$parallelIdentifier = (string) $input->getOption(Option::PARALLEL_IDENTIFIER);
36-
$outputFormat = (string) $input->getOption(Option::OUTPUT_FORMAT);
37-
/** @var string|null $memoryLimit */
38-
$memoryLimit = $input->getOption(Option::MEMORY_LIMIT);
29+
$paths = $this->resolvePaths($paths);
30+
$showProgressBar = $this->canShowProgressBar($debug, $outputFormat, $noProgressBar);
31+
$showErrorTable = !$noErrorTable;
32+
$showDiffs = !$noDiffs;
3933
$isParallel = SimpleParameterProvider::getBoolParameter(Option::PARALLEL);
4034
$isReportingWithRealPath = SimpleParameterProvider::getBoolParameter(Option::REPORTING_REALPATH);
41-
$config = $input->getOption(Option::CONFIG);
42-
if ($config !== null) {
43-
$config = (string) $config;
44-
}
4535
return new Configuration($isFixer, $shouldClearCache, $showProgressBar, $showErrorTable, $paths, $outputFormat, $isParallel, $config, $parallelPort, $parallelIdentifier, $memoryLimit, $showDiffs, $isReportingWithRealPath);
4636
}
47-
private function canShowProgressBar(InputInterface $input): bool
37+
private function canShowProgressBar(bool $debug, string $outputFormat, bool $noProgressBar): bool
4838
{
4939
// --debug option shows more
50-
$debug = (bool) $input->getOption(Option::DEBUG);
5140
if ($debug) {
5241
return \false;
5342
}
54-
$outputFormat = $input->getOption(Option::OUTPUT_FORMAT);
5543
$outputFormatter = $this->outputFormatterCollector->getByName($outputFormat);
5644
if (!$outputFormatter->hasSupportForProgressBars()) {
5745
return \false;
5846
}
59-
return !(bool) $input->getOption(Option::NO_PROGRESS_BAR);
47+
return !$noProgressBar;
6048
}
6149
/**
6250
* @param string[] $paths
@@ -71,12 +59,11 @@ private function ensurePathsExists(array $paths): void
7159
}
7260
}
7361
/**
62+
* @param string[] $paths
7463
* @return string[]
7564
*/
76-
private function resolvePaths(InputInterface $input): array
65+
private function resolvePaths(array $paths): array
7766
{
78-
/** @var string[] $paths */
79-
$paths = (array) $input->getArgument(Option::PATHS);
8067
if ($paths === []) {
8168
// if not paths are provided from CLI, use the config ones
8269
$paths = SimpleParameterProvider::getArrayParameter(Option::PATHS);

src/Console/Command/AbstractCheckCommand.php

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)