From 6fbc65a4b74449ac762f540da1dc09e2b022abb3 Mon Sep 17 00:00:00 2001 From: TomasVotruba Date: Thu, 9 Jan 2020 19:11:26 +0100 Subject: [PATCH] [ECS] Make phar ready by putting value objects to own namespace and exclude dir --- packages/EasyCodingStandard/bin/ecs | 117 +++++++++++++++--- .../compiler/build/scoper.inc.php | 7 +- .../EasyCodingStandard/compiler/composer.json | 1 - .../compiler/src/Console/CompileCommand.php | 35 +++++- .../src/Contract/Process/ProcessInterface.php | 12 -- .../Exception/ShouldNotHappenException.php | 11 ++ .../src/Process/CompileProcessFactory.php | 3 +- .../compiler/src/Process/SymfonyProcess.php | 15 +-- .../EasyCodingStandard/config/services.yaml | 13 +- .../Configuration/config/services.yaml | 2 +- .../packages/FixerRunner/config/services.yaml | 2 +- .../packages/SniffRunner/config/services.yaml | 4 +- .../src/Application/SniffFileProcessor.php | 2 +- .../SniffRunner/src/File/FileFactory.php | 1 + .../src/{File => ValueObject}/File.php | 2 +- .../tests/Application/FixerTest.php | 2 +- .../tests/Error/ErrorSorterTest.php | 2 +- .../tests/File/FileFactoryTest.php | 2 +- .../tests/ValueObject/FileSource/SomeFile.php | 3 + .../tests/{File => ValueObject}/FileTest.php | 6 +- .../Console/Output/ConsoleOutputFormatter.php | 2 +- .../Console/Output/JsonOutputFormatter.php | 4 +- .../Console/Style/EasyCodingStandardStyle.php | 2 +- .../src/Error/ErrorAndDiffCollector.php | 2 + .../src/Error/ErrorFactory.php | 1 + .../src/Error/ErrorSorter.php | 2 + .../src/Error/FileDiffFactory.php | 2 + .../src/{ => ValueObject}/Error/Error.php | 2 +- .../src/{ => ValueObject}/Error/FileDiff.php | 2 +- phpstan.neon | 5 +- 30 files changed, 187 insertions(+), 79 deletions(-) delete mode 100644 packages/EasyCodingStandard/compiler/src/Contract/Process/ProcessInterface.php create mode 100644 packages/EasyCodingStandard/compiler/src/Exception/ShouldNotHappenException.php rename packages/EasyCodingStandard/packages/SniffRunner/src/{File => ValueObject}/File.php (99%) create mode 100644 packages/EasyCodingStandard/packages/SniffRunner/tests/ValueObject/FileSource/SomeFile.php rename packages/EasyCodingStandard/packages/SniffRunner/tests/{File => ValueObject}/FileTest.php (89%) rename packages/EasyCodingStandard/src/{ => ValueObject}/Error/Error.php (94%) rename packages/EasyCodingStandard/src/{ => ValueObject}/Error/FileDiff.php (95%) diff --git a/packages/EasyCodingStandard/bin/ecs b/packages/EasyCodingStandard/bin/ecs index 39c4a15785d..3f3aca788cb 100755 --- a/packages/EasyCodingStandard/bin/ecs +++ b/packages/EasyCodingStandard/bin/ecs @@ -17,26 +17,10 @@ use Symplify\EasyCodingStandard\Configuration\Configuration; gc_disable(); # 1. autoload -$possibleAutoloadPaths = [ - // after split package - __DIR__ . '/../vendor', - // dependency - __DIR__ . '/../../..', - // monorepo - __DIR__ . '/../../../vendor', -]; - -foreach ($possibleAutoloadPaths as $possibleAutoloadPath) { - if (is_file($possibleAutoloadPath . '/autoload.php')) { - require_once $possibleAutoloadPath . '/autoload.php'; - require_once $possibleAutoloadPath . '/squizlabs/php_codesniffer/autoload.php'; - - // initalize PHPCS tokens - new Tokens(); - - break; - } -} +$autoloadIncluder = new AutoloadIncluder(); +$autoloadIncluder->includeCwdVendorAutoloadIfExists(); +$autoloadIncluder->autoloadProjectAutoloaderFile('/../../autoload.php'); +$autoloadIncluder->includeDependencyOrRepositoryVendorAutoloadIfExists(); # 2. create container $configs = []; @@ -112,3 +96,96 @@ $configuration->setFirstResolverConfig($configResolver->getFirstResolvedConfig() # 3. run $application = $container->get(EasyCodingStandardConsoleApplication::class); exit($application->run()); + + +/** + * Inspired by https://github.com/rectorphp/rector/pull/2373/files#diff-0fc04a2bb7928cac4ae339d5a8bf67f3 + */ +final class AutoloadIncluder +{ + /** + * @var string[] + */ + private $alreadyLoadedAutoloadFiles = []; + + public function includeCwdVendorAutoloadIfExists(): void + { + $cwdVendorAutoload = getcwd() . '/vendor/autoload.php'; + if (!is_file($cwdVendorAutoload)) { + return; + } + $this->loadIfNotLoadedYet($cwdVendorAutoload, __METHOD__ . '()" on line ' . __LINE__); + } + + public function includeDependencyOrRepositoryVendorAutoloadIfExists(): void + { + // ECS' vendor is already loaded + if (class_exists('\Symplify\EasyCodingStandard\HttpKernel\EasyCodingStandardKernel')) { + return; + } + + $devOrPharVendorAutoload = __DIR__ . '/../vendor/autoload.php'; + if (! is_file($devOrPharVendorAutoload)) { + return; + } + + $this->loadIfNotLoadedYet($devOrPharVendorAutoload, __METHOD__ . '()" on line ' . __LINE__); + } + /** + * Inspired by https://github.com/phpstan/phpstan-src/blob/e2308ecaf49a9960510c47f5a992ce7b27f6dba2/bin/phpstan#L19 + */ + public function autoloadProjectAutoloaderFile(string $file): void + { + $path = dirname(__DIR__) . $file; + if (!extension_loaded('phar')) { + if (is_file($path)) { + $this->loadIfNotLoadedYet($path, __METHOD__ . '()" on line ' . __LINE__); + } + } else { + $pharPath = Phar::running(false); + if ($pharPath === '') { + if (is_file($path)) { + $this->loadIfNotLoadedYet($path, __METHOD__ . '()" on line ' . __LINE__); + } + } else { + $path = dirname($pharPath) . $file; + if (is_file($path)) { + $this->loadIfNotLoadedYet($path, __METHOD__ . '()" on line ' . __LINE__); + } + } + } + } + + private function loadIfNotLoadedYet(string $file, string $location): void + { + if (in_array($file, $this->alreadyLoadedAutoloadFiles, true)) { + return; + } + + if ($this->isDebugOption()) { + echo sprintf(sprintf( + 'File "%s" is about to be loaded in "%s"' . PHP_EOL, + $file, + $location + )); + } + + $this->alreadyLoadedAutoloadFiles[] = realpath($file); + require_once $file; + + $phpCodeSnifferAutoload = dirname($file) . '/squizlabs/php_codesniffer/autoload.php'; + if (!file_exists($phpCodeSnifferAutoload)) { + return; + } + + require_once $phpCodeSnifferAutoload; + + // initalize PHPCS tokens + new Tokens(); + } + + private function isDebugOption(): bool + { + return in_array('--debug', $_SERVER['argv'], true); + } +} diff --git a/packages/EasyCodingStandard/compiler/build/scoper.inc.php b/packages/EasyCodingStandard/compiler/build/scoper.inc.php index 8357ece4d93..09848bc6894 100644 --- a/packages/EasyCodingStandard/compiler/build/scoper.inc.php +++ b/packages/EasyCodingStandard/compiler/build/scoper.inc.php @@ -15,5 +15,10 @@ function (string $filePath, string $prefix, string $content): string { return str_replace('__DIR__ . \'/..', '\'phar://ecs.phar', $content); }, ], - 'whitelist' => ['Symplify\*', 'PHP_CodeSniffer\*', 'PhpCsFixer\*'], + 'whitelist' => [ + 'Symplify\EasyCodingStandard\*', + 'Symplify\CodingStandard\*', + 'PHP_CodeSniffer\*', + 'PhpCsFixer\*', + ], ]; diff --git a/packages/EasyCodingStandard/compiler/composer.json b/packages/EasyCodingStandard/compiler/composer.json index 848f5933171..5c5ae66e6af 100644 --- a/packages/EasyCodingStandard/compiler/composer.json +++ b/packages/EasyCodingStandard/compiler/composer.json @@ -9,7 +9,6 @@ "symfony/console": "^4.4|^5.0", "symfony/filesystem": "^4.4|^5.0", "symfony/finder": "^4.4|^5.0", - "symfony/polyfill-php73": "^1.13", "symfony/process": "^4.4|^5.0" }, "require-dev": { diff --git a/packages/EasyCodingStandard/compiler/src/Console/CompileCommand.php b/packages/EasyCodingStandard/compiler/src/Console/CompileCommand.php index 2f5bb743984..dd444247785 100644 --- a/packages/EasyCodingStandard/compiler/src/Console/CompileCommand.php +++ b/packages/EasyCodingStandard/compiler/src/Console/CompileCommand.php @@ -12,6 +12,7 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Filesystem\Filesystem; +use Symplify\EasyCodingStandard\Compiler\Exception\ShouldNotHappenException; use Symplify\EasyCodingStandard\Compiler\Process\CompileProcessFactory; /** @@ -35,7 +36,7 @@ final class CompileCommand extends Command private $originalComposerJsonFileContent; /** - * @var string + * @var string|null */ private $symplifyVersionToRequire; @@ -77,6 +78,12 @@ protected function execute(InputInterface $input, OutputInterface $output): int $this->buildDir ); + // remove bugging packages + $dirsToRemove = [__DIR__ . '/../../vendor/symfony/polyfill-php70']; + foreach ($dirsToRemove as $dirToRemove) { + NetteFileSystem::delete($dirToRemove); + } + // parallel prevention is just for single less-buggy process $this->compileProcessFactory->create(['php', 'box.phar', 'compile', '--no-parallel'], $this->dataDir); @@ -98,6 +105,11 @@ private function fixComposerJson(string $composerJsonFile): void // simplify autoload (remove not packed build directory] $json['autoload']['psr-4']['Symplify\\EasyCodingStandard\\'] = 'src'; + // remove dev content + unset($json['minimum-stability']); + unset($json['prefer-stable']); + unset($json['extra']); + // use stable version for symplify packages foreach (array_keys($json['require']) as $package) { /** @var string $package */ @@ -109,6 +121,15 @@ private function fixComposerJson(string $composerJsonFile): void $json['require'][$package] = $symplifyVersionToRequire; } + // cleanup + $filesToRemove = [ + __DIR__ . '/../../../vendor/friendsofphp/php-cs-fixer/src/Test/AbstractIntegrationTestCase.php', + ]; + + foreach ($filesToRemove as $fileToRemove) { + NetteFileSystem::delete($fileToRemove); + } + $encodedJson = Json::encode($json, Json::PRETTY); $this->filesystem->dumpFile($composerJsonFile, $encodedJson); @@ -126,14 +147,20 @@ private function restoreComposerJson(string $composerJsonFile): void private function getSymplifyStableVersionToRequire(): string { - if ($this->symplifyVersionToRequire) { + if ($this->symplifyVersionToRequire !== null) { return $this->symplifyVersionToRequire; } - $symplifyPackageContent = NetteFileSystem::read('https://repo.packagist.org/p/symplify/symplify.json'); + $symplifyPackageContent = file_get_contents('https://repo.packagist.org/p/symplify/symplify.json'); + if ($symplifyPackageContent === null) { + throw new ShouldNotHappenException(); + } + $symplifyPackageJson = Json::decode($symplifyPackageContent, Json::FORCE_ARRAY); + $symplifyPackageVersions = $symplifyPackageJson['packages']['symplify/symplify']; + end($symplifyPackageVersions); - $lastStableVersion = array_key_last($symplifyPackageJson['packages']['symplify/symplify']); + $lastStableVersion = key($symplifyPackageVersions); $lastStableVersion = new Version($lastStableVersion); $this->symplifyVersionToRequire = '^' . $lastStableVersion->getMajor()->getValue() . '.' . $lastStableVersion->getMinor()->getValue(); diff --git a/packages/EasyCodingStandard/compiler/src/Contract/Process/ProcessInterface.php b/packages/EasyCodingStandard/compiler/src/Contract/Process/ProcessInterface.php deleted file mode 100644 index 6016d8e4bc1..00000000000 --- a/packages/EasyCodingStandard/compiler/src/Contract/Process/ProcessInterface.php +++ /dev/null @@ -1,12 +0,0 @@ -output); } diff --git a/packages/EasyCodingStandard/compiler/src/Process/SymfonyProcess.php b/packages/EasyCodingStandard/compiler/src/Process/SymfonyProcess.php index a058012d14f..35e0d4fbe78 100644 --- a/packages/EasyCodingStandard/compiler/src/Process/SymfonyProcess.php +++ b/packages/EasyCodingStandard/compiler/src/Process/SymfonyProcess.php @@ -6,28 +6,17 @@ use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Process\Process; -use Symplify\EasyCodingStandard\Compiler\Contract\Process\ProcessInterface; -final class SymfonyProcess implements ProcessInterface +final class SymfonyProcess { - /** - * @var Process - */ - private $process; - /** * @param string[] $command */ public function __construct(array $command, string $cwd, OutputInterface $output) { - $this->process = (new Process($command, $cwd, null, null, null)) + (new Process($command, $cwd, null, null, null)) ->mustRun(static function (string $type, string $buffer) use ($output): void { $output->write($buffer); }); } - - public function getProcess(): Process - { - return $this->process; - } } diff --git a/packages/EasyCodingStandard/config/services.yaml b/packages/EasyCodingStandard/config/services.yaml index 50685e95b83..ef29aa1003f 100644 --- a/packages/EasyCodingStandard/config/services.yaml +++ b/packages/EasyCodingStandard/config/services.yaml @@ -9,13 +9,12 @@ services: Symplify\EasyCodingStandard\: resource: '../src' exclude: - - '../src/Contract' - - '../src/DependencyInjection' - - '../src/HttpKernel' - - '../src/Exception' - - '../src/Error/Error.php' - - '../src/Error/FileDiff.php' - - '../src/Yaml' + - '../src/Contract/*' + - '../src/DependencyInjection/*' + - '../src/HttpKernel/*' + - '../src/Exception/*' + - '../src/ValueObject/*' + - '../src/Yaml/*' _instanceof: Symplify\EasyCodingStandard\Contract\Application\FileProcessorCollectorInterface: diff --git a/packages/EasyCodingStandard/packages/Configuration/config/services.yaml b/packages/EasyCodingStandard/packages/Configuration/config/services.yaml index c009c6caf35..2e1fb0cdafa 100644 --- a/packages/EasyCodingStandard/packages/Configuration/config/services.yaml +++ b/packages/EasyCodingStandard/packages/Configuration/config/services.yaml @@ -6,4 +6,4 @@ services: Symplify\EasyCodingStandard\Configuration\: resource: '../src' exclude: - - '../src/Exception' + - '../src/Exception/*' diff --git a/packages/EasyCodingStandard/packages/FixerRunner/config/services.yaml b/packages/EasyCodingStandard/packages/FixerRunner/config/services.yaml index f8ea95f9c49..efc62e2ce66 100644 --- a/packages/EasyCodingStandard/packages/FixerRunner/config/services.yaml +++ b/packages/EasyCodingStandard/packages/FixerRunner/config/services.yaml @@ -6,7 +6,7 @@ services: Symplify\EasyCodingStandard\FixerRunner\: resource: '../src' exclude: - - '../src/Exception' + - '../src/Exception/*' # differ PhpCsFixer\Differ\UnifiedDiffer: ~ diff --git a/packages/EasyCodingStandard/packages/SniffRunner/config/services.yaml b/packages/EasyCodingStandard/packages/SniffRunner/config/services.yaml index 7e0c50c449d..21f85df7c09 100644 --- a/packages/EasyCodingStandard/packages/SniffRunner/config/services.yaml +++ b/packages/EasyCodingStandard/packages/SniffRunner/config/services.yaml @@ -6,5 +6,5 @@ services: Symplify\EasyCodingStandard\SniffRunner\: resource: '../src' exclude: - - '../src/Exception' - - '../src/File/File.php' + - '../src/Exception/*' + - '../src/ValueObject/*' diff --git a/packages/EasyCodingStandard/packages/SniffRunner/src/Application/SniffFileProcessor.php b/packages/EasyCodingStandard/packages/SniffRunner/src/Application/SniffFileProcessor.php index 2a95418993e..c0d8e805bad 100644 --- a/packages/EasyCodingStandard/packages/SniffRunner/src/Application/SniffFileProcessor.php +++ b/packages/EasyCodingStandard/packages/SniffRunner/src/Application/SniffFileProcessor.php @@ -16,8 +16,8 @@ use Symplify\EasyCodingStandard\Contract\Application\DualRunInterface; use Symplify\EasyCodingStandard\Contract\Application\FileProcessorInterface; use Symplify\EasyCodingStandard\Error\ErrorAndDiffCollector; -use Symplify\EasyCodingStandard\SniffRunner\File\File; use Symplify\EasyCodingStandard\SniffRunner\File\FileFactory; +use Symplify\EasyCodingStandard\SniffRunner\ValueObject\File; use Symplify\SmartFileSystem\SmartFileInfo; final class SniffFileProcessor implements FileProcessorInterface, DualRunAwareFileProcessorInterface diff --git a/packages/EasyCodingStandard/packages/SniffRunner/src/File/FileFactory.php b/packages/EasyCodingStandard/packages/SniffRunner/src/File/FileFactory.php index 2dea10aa624..d3547a2f1ad 100644 --- a/packages/EasyCodingStandard/packages/SniffRunner/src/File/FileFactory.php +++ b/packages/EasyCodingStandard/packages/SniffRunner/src/File/FileFactory.php @@ -9,6 +9,7 @@ use Symplify\EasyCodingStandard\Console\Style\EasyCodingStandardStyle; use Symplify\EasyCodingStandard\Error\ErrorAndDiffCollector; use Symplify\EasyCodingStandard\Skipper; +use Symplify\EasyCodingStandard\SniffRunner\ValueObject\File; use Symplify\SmartFileSystem\SmartFileInfo; final class FileFactory diff --git a/packages/EasyCodingStandard/packages/SniffRunner/src/File/File.php b/packages/EasyCodingStandard/packages/SniffRunner/src/ValueObject/File.php similarity index 99% rename from packages/EasyCodingStandard/packages/SniffRunner/src/File/File.php rename to packages/EasyCodingStandard/packages/SniffRunner/src/ValueObject/File.php index 0a2308e18e4..aecdf584570 100644 --- a/packages/EasyCodingStandard/packages/SniffRunner/src/File/File.php +++ b/packages/EasyCodingStandard/packages/SniffRunner/src/ValueObject/File.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Symplify\EasyCodingStandard\SniffRunner\File; +namespace Symplify\EasyCodingStandard\SniffRunner\ValueObject; use PHP_CodeSniffer\Config; use PHP_CodeSniffer\Files\File as BaseFile; diff --git a/packages/EasyCodingStandard/packages/SniffRunner/tests/Application/FixerTest.php b/packages/EasyCodingStandard/packages/SniffRunner/tests/Application/FixerTest.php index c5c6c299806..ebe54092665 100644 --- a/packages/EasyCodingStandard/packages/SniffRunner/tests/Application/FixerTest.php +++ b/packages/EasyCodingStandard/packages/SniffRunner/tests/Application/FixerTest.php @@ -6,8 +6,8 @@ use PHP_CodeSniffer\Fixer; use Symplify\EasyCodingStandard\HttpKernel\EasyCodingStandardKernel; -use Symplify\EasyCodingStandard\SniffRunner\File\File; use Symplify\EasyCodingStandard\SniffRunner\File\FileFactory; +use Symplify\EasyCodingStandard\SniffRunner\ValueObject\File; use Symplify\PackageBuilder\Tests\AbstractKernelTestCase; use Symplify\SmartFileSystem\SmartFileInfo; diff --git a/packages/EasyCodingStandard/packages/SniffRunner/tests/Error/ErrorSorterTest.php b/packages/EasyCodingStandard/packages/SniffRunner/tests/Error/ErrorSorterTest.php index 042980e6c33..031bba28c9d 100644 --- a/packages/EasyCodingStandard/packages/SniffRunner/tests/Error/ErrorSorterTest.php +++ b/packages/EasyCodingStandard/packages/SniffRunner/tests/Error/ErrorSorterTest.php @@ -4,10 +4,10 @@ namespace Symplify\EasyCodingStandard\SniffRunner\Tests\Error; -use Symplify\EasyCodingStandard\Error\Error; use Symplify\EasyCodingStandard\Error\ErrorFactory; use Symplify\EasyCodingStandard\Error\ErrorSorter; use Symplify\EasyCodingStandard\HttpKernel\EasyCodingStandardKernel; +use Symplify\EasyCodingStandard\ValueObject\Error\Error; use Symplify\PackageBuilder\Tests\AbstractKernelTestCase; use Symplify\SmartFileSystem\SmartFileInfo; diff --git a/packages/EasyCodingStandard/packages/SniffRunner/tests/File/FileFactoryTest.php b/packages/EasyCodingStandard/packages/SniffRunner/tests/File/FileFactoryTest.php index 72e2165c38d..7acd374e516 100644 --- a/packages/EasyCodingStandard/packages/SniffRunner/tests/File/FileFactoryTest.php +++ b/packages/EasyCodingStandard/packages/SniffRunner/tests/File/FileFactoryTest.php @@ -7,8 +7,8 @@ use PHP_CodeSniffer\Files\File as PhpCodeSnifferFile; use PHP_CodeSniffer\Fixer; use Symplify\EasyCodingStandard\HttpKernel\EasyCodingStandardKernel; -use Symplify\EasyCodingStandard\SniffRunner\File\File; use Symplify\EasyCodingStandard\SniffRunner\File\FileFactory; +use Symplify\EasyCodingStandard\SniffRunner\ValueObject\File; use Symplify\PackageBuilder\Tests\AbstractKernelTestCase; use Symplify\SmartFileSystem\SmartFileInfo; diff --git a/packages/EasyCodingStandard/packages/SniffRunner/tests/ValueObject/FileSource/SomeFile.php b/packages/EasyCodingStandard/packages/SniffRunner/tests/ValueObject/FileSource/SomeFile.php new file mode 100644 index 00000000000..174d7fd709f --- /dev/null +++ b/packages/EasyCodingStandard/packages/SniffRunner/tests/ValueObject/FileSource/SomeFile.php @@ -0,0 +1,3 @@ +errorAndDiffCollector = self::$container->get(ErrorAndDiffCollector::class); $fileFactory = self::$container->get(FileFactory::class); - $fileInfo = new SmartFileInfo(__DIR__ . '/FileFactorySource/SomeFile.php'); + $fileInfo = new SmartFileInfo(__DIR__ . '/FileSource/SomeFile.php'); $this->file = $fileFactory->createFromFileInfo($fileInfo); $this->file->processWithTokenListenersAndFileInfo([], $fileInfo); diff --git a/packages/EasyCodingStandard/src/Console/Output/ConsoleOutputFormatter.php b/packages/EasyCodingStandard/src/Console/Output/ConsoleOutputFormatter.php index a59646cad4c..434f4be764b 100644 --- a/packages/EasyCodingStandard/src/Console/Output/ConsoleOutputFormatter.php +++ b/packages/EasyCodingStandard/src/Console/Output/ConsoleOutputFormatter.php @@ -8,7 +8,7 @@ use Symplify\EasyCodingStandard\Console\Style\EasyCodingStandardStyle; use Symplify\EasyCodingStandard\Contract\Console\Output\OutputFormatterInterface; use Symplify\EasyCodingStandard\Error\ErrorAndDiffCollector; -use Symplify\EasyCodingStandard\Error\FileDiff; +use Symplify\EasyCodingStandard\ValueObject\Error\FileDiff; use Symplify\PackageBuilder\Console\ShellCode; final class ConsoleOutputFormatter implements OutputFormatterInterface diff --git a/packages/EasyCodingStandard/src/Console/Output/JsonOutputFormatter.php b/packages/EasyCodingStandard/src/Console/Output/JsonOutputFormatter.php index 7e0ba82fadf..18d5d0bc90f 100644 --- a/packages/EasyCodingStandard/src/Console/Output/JsonOutputFormatter.php +++ b/packages/EasyCodingStandard/src/Console/Output/JsonOutputFormatter.php @@ -8,9 +8,9 @@ use Symplify\EasyCodingStandard\Configuration\Configuration; use Symplify\EasyCodingStandard\Console\Style\EasyCodingStandardStyle; use Symplify\EasyCodingStandard\Contract\Console\Output\OutputFormatterInterface; -use Symplify\EasyCodingStandard\Error\Error; use Symplify\EasyCodingStandard\Error\ErrorAndDiffCollector; -use Symplify\EasyCodingStandard\Error\FileDiff; +use Symplify\EasyCodingStandard\ValueObject\Error\Error; +use Symplify\EasyCodingStandard\ValueObject\Error\FileDiff; use Symplify\PackageBuilder\Console\ShellCode; final class JsonOutputFormatter implements OutputFormatterInterface diff --git a/packages/EasyCodingStandard/src/Console/Style/EasyCodingStandardStyle.php b/packages/EasyCodingStandard/src/Console/Style/EasyCodingStandardStyle.php index d3a824dadf7..1def668d89b 100644 --- a/packages/EasyCodingStandard/src/Console/Style/EasyCodingStandardStyle.php +++ b/packages/EasyCodingStandard/src/Console/Style/EasyCodingStandardStyle.php @@ -8,7 +8,7 @@ use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; use Symfony\Component\Console\Terminal; -use Symplify\EasyCodingStandard\Error\Error; +use Symplify\EasyCodingStandard\ValueObject\Error\Error; final class EasyCodingStandardStyle extends SymfonyStyle { diff --git a/packages/EasyCodingStandard/src/Error/ErrorAndDiffCollector.php b/packages/EasyCodingStandard/src/Error/ErrorAndDiffCollector.php index 14037cb01a7..eebf5f08147 100644 --- a/packages/EasyCodingStandard/src/Error/ErrorAndDiffCollector.php +++ b/packages/EasyCodingStandard/src/Error/ErrorAndDiffCollector.php @@ -6,6 +6,8 @@ use Nette\Utils\Arrays; use Symplify\EasyCodingStandard\ChangedFilesDetector\ChangedFilesDetector; +use Symplify\EasyCodingStandard\ValueObject\Error\Error; +use Symplify\EasyCodingStandard\ValueObject\Error\FileDiff; use Symplify\SmartFileSystem\SmartFileInfo; final class ErrorAndDiffCollector diff --git a/packages/EasyCodingStandard/src/Error/ErrorFactory.php b/packages/EasyCodingStandard/src/Error/ErrorFactory.php index 747fa4aab36..ad09a260456 100644 --- a/packages/EasyCodingStandard/src/Error/ErrorFactory.php +++ b/packages/EasyCodingStandard/src/Error/ErrorFactory.php @@ -4,6 +4,7 @@ namespace Symplify\EasyCodingStandard\Error; +use Symplify\EasyCodingStandard\ValueObject\Error\Error; use Symplify\SmartFileSystem\SmartFileInfo; final class ErrorFactory diff --git a/packages/EasyCodingStandard/src/Error/ErrorSorter.php b/packages/EasyCodingStandard/src/Error/ErrorSorter.php index d7f20aa0c82..26076b22dea 100644 --- a/packages/EasyCodingStandard/src/Error/ErrorSorter.php +++ b/packages/EasyCodingStandard/src/Error/ErrorSorter.php @@ -4,6 +4,8 @@ namespace Symplify\EasyCodingStandard\Error; +use Symplify\EasyCodingStandard\ValueObject\Error\Error; + final class ErrorSorter { /** diff --git a/packages/EasyCodingStandard/src/Error/FileDiffFactory.php b/packages/EasyCodingStandard/src/Error/FileDiffFactory.php index 0ab1b705f75..18f9755b2e3 100644 --- a/packages/EasyCodingStandard/src/Error/FileDiffFactory.php +++ b/packages/EasyCodingStandard/src/Error/FileDiffFactory.php @@ -4,6 +4,8 @@ namespace Symplify\EasyCodingStandard\Error; +use Symplify\EasyCodingStandard\ValueObject\Error\FileDiff; + final class FileDiffFactory { /** diff --git a/packages/EasyCodingStandard/src/Error/Error.php b/packages/EasyCodingStandard/src/ValueObject/Error/Error.php similarity index 94% rename from packages/EasyCodingStandard/src/Error/Error.php rename to packages/EasyCodingStandard/src/ValueObject/Error/Error.php index 2a2270c4d94..052f197ee3c 100644 --- a/packages/EasyCodingStandard/src/Error/Error.php +++ b/packages/EasyCodingStandard/src/ValueObject/Error/Error.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Symplify\EasyCodingStandard\Error; +namespace Symplify\EasyCodingStandard\ValueObject\Error; use Symplify\SmartFileSystem\SmartFileInfo; diff --git a/packages/EasyCodingStandard/src/Error/FileDiff.php b/packages/EasyCodingStandard/src/ValueObject/Error/FileDiff.php similarity index 95% rename from packages/EasyCodingStandard/src/Error/FileDiff.php rename to packages/EasyCodingStandard/src/ValueObject/Error/FileDiff.php index a51a9789b19..8a94476ff02 100644 --- a/packages/EasyCodingStandard/src/Error/FileDiff.php +++ b/packages/EasyCodingStandard/src/ValueObject/Error/FileDiff.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Symplify\EasyCodingStandard\Error; +namespace Symplify\EasyCodingStandard\ValueObject\Error; use PhpCsFixer\Differ\DiffConsoleFormatter; diff --git a/phpstan.neon b/phpstan.neon index 5ba195a8b6b..b9743f87539 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -18,7 +18,7 @@ parameters: # Symfony workaround - packages/ChangelogLinker/src/DependencyInjection/Dummy/ResolveAutowiringExceptionHelper.php # 3rd party - - packages/EasyCodingStandard/packages/SniffRunner/src/File/File.php + - packages/EasyCodingStandard/packages/SniffRunner/src/ValueObject/File.php # tests - packages/PHPStanExtensions/tests/Rules/ClassMethod/Source/* - packages/EasyCodingStandard/compiler/vendor/* @@ -133,3 +133,6 @@ parameters: - '#in iterable type#' - '#Method Symplify\\PHPStanExtensions\\Tests\\Rules\\Classes\\MatchingTypeConstantRuleTest\:\:getRule\(\) return type with generic interface PHPStan\\Rules\\Rule does not specify its types\: TNodeType#' - '#Class Symplify\\PHPStanExtensions\\Rules\\ClassMethod\\BoolishClassMethodPrefixRule implements generic interface PHPStan\\Rules\\Rule but does not specify its types\: TNodeType#' + + - '#Strict comparison using \=\=\= between string\|false and null will always evaluate to false#' + - '#Parameter \#1 \$json of static method Nette\\Utils\\Json\:\:decode\(\) expects string, string\|false given#'