diff --git a/.github/workflows/ecs_prefixed.yaml b/.github/workflows/ecs_prefixed.yaml index 31b17f4d772..2390e6d488e 100644 --- a/.github/workflows/ecs_prefixed.yaml +++ b/.github/workflows/ecs_prefixed.yaml @@ -39,14 +39,18 @@ jobs: - name: Run ecs.phar run: | - cd packages/EasyCodingStandard/compiler - ../tmp/ecs.phar + # remove local vendor, to prevent duplicated content + rm -rf packages/EasyCodingStandard/vendor + cd packages/EasyCodingStandard + tmp/ecs.phar - name: Run ecs.phar with PSR-12 set run: | - cd packages/EasyCodingStandard/compiler - ../tmp/ecs.phar check ../src --set psr12 --dry-run --debug + cd packages/EasyCodingStandard + # create dummy file + echo "> someFile.php + tmp/ecs.phar check someFile.php --set dead-code # Deploy PHAR to https://github.com/Symplify/EasyCodingStandardPrefixed - @@ -57,19 +61,23 @@ jobs: # reuse tmp/ecs.phar from previous job git clone https://${ACCESS_TOKEN}@github.com/Symplify/EasyCodingStandardPrefixed.git > /dev/null 2>&1 + # copy phar files inside cloned repository cp tmp/ecs.phar EasyCodingStandardPrefixed/ecs.phar cp tmp/ecs.phar EasyCodingStandardPrefixed/ecs - cd EasyCodingStandardPrefixed + # go to clone repository + cd EasyCodingStandardPrefixed git config user.email "action@github.com" git config user.name "Github Actions" git add ecs ecs.phar + # commit with new tag, if this commit is tagged, or with normal commit if [ "${TRAVIS_TAG}" != "" ]; then COMMIT_MSG="ECS ${TRAVIS_TAG}"; else COMMIT_MSG="Updated ECS to commit ${TRAVIS_COMMIT}"; fi - git commit -m "${COMMIT_MSG}" + git push --quiet origin master + # push tag, if this commit is tagged, or with normal push if [ "${TRAVIS_TAG}" != "" ]; then git tag "${TRAVIS_TAG}" && git push --quiet origin ${TRAVIS_TAG}; fi env: ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }} diff --git a/packages/EasyCodingStandard/bin/ecs b/packages/EasyCodingStandard/bin/ecs index 8348a4bc376..3f841d3f356 100755 --- a/packages/EasyCodingStandard/bin/ecs +++ b/packages/EasyCodingStandard/bin/ecs @@ -23,8 +23,6 @@ $autoloadIncluder->autoloadProjectAutoloaderFile('/../../autoload.php'); $autoloadIncluder->includeDependencyOrRepositoryVendorAutoloadIfExists(); $autoloadIncluder->includePhpCodeSnifferAutoloadIfNotInPharAndInitliazeTokens(); - - # 2. create container $configs = []; @@ -35,7 +33,6 @@ $input = new ArgvInput(); $inputConfig = $configResolver->resolveFromInputWithFallback($input, ['easy-coding-standard.yml', 'easy-coding-standard.yaml', 'ecs.yml', 'ecs.yaml'] ); - if ($inputConfig) { $configs[] = $inputConfig; } @@ -48,7 +45,6 @@ if ($setInputConfig) { // 3. "parameters > set" in provided yaml files $parameterSetsConfigs = $configResolver->resolveFromParameterSetsFromConfigFiles($configs, Set::SET_DIRECTORY); - if ($parameterSetsConfigs !== []) { $configs = array_merge($configs, $parameterSetsConfigs); } @@ -76,8 +72,9 @@ foreach ($configs as $config) { } } -$mainConfigShiftedAsLast[] = $inputConfig; - +if ($inputConfig !== null) { + $mainConfigShiftedAsLast[] = $inputConfig; +} $easyCodingStandardKernel = new EasyCodingStandardKernel($environment, InputDetector::isDebug()); if ($configs !== []) { diff --git a/packages/EasyCodingStandard/compiler/README.md b/packages/EasyCodingStandard/compiler/README.md index d9bf207118b..a6212c5ea86 100644 --- a/packages/EasyCodingStandard/compiler/README.md +++ b/packages/EasyCodingStandard/compiler/README.md @@ -14,3 +14,16 @@ php ../tmp/ecs.phar ``` Please note that running the compiler will change the contents of `composer.json` file and `vendor` directory. Revert those changes after running it. + +## Notes + +This section si needed in `composer.json`, because it was causing autolaoding bugs. +Box aliases existing Symfony stubs to php, see https://ayesh.me/composer-replace-polyfills. + +```json +{ + "replace": { + "symfony/polyfill-php70": "*" + } +} +``` diff --git a/packages/EasyCodingStandard/compiler/src/Console/CompileCommand.php b/packages/EasyCodingStandard/compiler/src/Console/CompileCommand.php index a7308b22c09..06555087fee 100644 --- a/packages/EasyCodingStandard/compiler/src/Console/CompileCommand.php +++ b/packages/EasyCodingStandard/compiler/src/Console/CompileCommand.php @@ -7,12 +7,11 @@ use Nette\Utils\FileSystem as NetteFileSystem; use Nette\Utils\Json; use Nette\Utils\Strings; -use PharIo\Version\Version; use Symfony\Component\Console\Command\Command; 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\Packagist\SymplifyStableVersionProvider; use Symplify\EasyCodingStandard\Compiler\Process\CompileProcessFactory; /** @@ -35,11 +34,6 @@ final class CompileCommand extends Command */ private $originalComposerJsonFileContent; - /** - * @var string|null - */ - private $symplifyVersionToRequire; - /** * @var Filesystem */ @@ -50,6 +44,11 @@ final class CompileCommand extends Command */ private $compileProcessFactory; + /** + * @var SymplifyStableVersionProvider + */ + private $symplifyStableVersionProvider; + public function __construct(CompileProcessFactory $compileProcessFactory, string $dataDir, string $buildDir) { parent::__construct(); @@ -57,6 +56,7 @@ public function __construct(CompileProcessFactory $compileProcessFactory, string $this->compileProcessFactory = $compileProcessFactory; $this->dataDir = $dataDir; $this->buildDir = $buildDir; + $this->symplifyStableVersionProvider = new SymplifyStableVersionProvider(); } protected function configure(): void @@ -78,12 +78,6 @@ 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); @@ -120,32 +114,9 @@ private function restoreComposerJson(string $composerJsonFile): void // re-run @todo composer update on root } - private function getSymplifyStableVersionToRequire(): string - { - if ($this->symplifyVersionToRequire !== null) { - return $this->symplifyVersionToRequire; - } - - $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 = key($symplifyPackageVersions); - $lastStableVersion = new Version($lastStableVersion); - - $this->symplifyVersionToRequire = '^' . $lastStableVersion->getMajor()->getValue() . '.' . $lastStableVersion->getMinor()->getValue(); - - return $this->symplifyVersionToRequire; - } - private function replaceDevSymplifyVersionWithLastStableVersion(array $json): array { - $symplifyVersionToRequire = $this->getSymplifyStableVersionToRequire(); + $symplifyVersionToRequire = $this->symplifyStableVersionProvider->provide(); foreach (array_keys($json['require']) as $package) { /** @var string $package */ diff --git a/packages/EasyCodingStandard/compiler/src/Packagist/SymplifyStableVersionProvider.php b/packages/EasyCodingStandard/compiler/src/Packagist/SymplifyStableVersionProvider.php new file mode 100644 index 00000000000..41601fc049d --- /dev/null +++ b/packages/EasyCodingStandard/compiler/src/Packagist/SymplifyStableVersionProvider.php @@ -0,0 +1,52 @@ +symplifyVersionToRequire !== null) { + return $this->symplifyVersionToRequire; + } + + $symplifyPackageContent = file_get_contents('https://repo.packagist.org/p/symplify/symplify.json'); + if ($symplifyPackageContent === null) { + throw new ShouldNotHappenException(); + } + + $symplifyPackageJson = $this->loadContentJsonStringToArray($symplifyPackageContent); + $symplifyPackageVersions = $symplifyPackageJson['packages']['symplify/symplify']; + + $lastStableVersion = $this->getLastKey($symplifyPackageVersions); + + $lastStableVersion = new Version($lastStableVersion); + + $this->symplifyVersionToRequire = '^' . $lastStableVersion->getMajor()->getValue() . '.' . $lastStableVersion->getMinor()->getValue(); + + return $this->symplifyVersionToRequire; + } + + private function loadContentJsonStringToArray(string $jsonContent): array + { + return Json::decode($jsonContent, Json::FORCE_ARRAY); + } + + private function getLastKey(array $items): string + { + end($items); + + return key($items); + } +} diff --git a/packages/EasyCodingStandard/composer.json b/packages/EasyCodingStandard/composer.json index 820540102af..987ec3a9440 100644 --- a/packages/EasyCodingStandard/composer.json +++ b/packages/EasyCodingStandard/composer.json @@ -30,6 +30,10 @@ "symplify/autowire-array-parameter": "^7.3", "symplify/auto-bind-parameter": "^7.3" }, + "require-dev": { + "phpunit/phpunit": "^8.5", + "symplify/easy-coding-standard-tester": "^7.3" + }, "autoload": { "psr-4": { "Symplify\\EasyCodingStandard\\": "src", @@ -38,5 +42,23 @@ "Symplify\\EasyCodingStandard\\FixerRunner\\": "packages/FixerRunner/src", "Symplify\\EasyCodingStandard\\SniffRunner\\": "packages/SniffRunner/src" } - } + }, + "autoload-dev": { + "psr-4": { + "Symplify\\EasyCodingStandard\\ChangedFilesDetector\\Tests\\": "packages/ChangedFilesDetector/tests", + "Symplify\\EasyCodingStandard\\FixerRunner\\Tests\\": "packages/FixerRunner/tests", + "Symplify\\EasyCodingStandard\\SniffRunner\\Tests\\": "packages/SniffRunner/tests", + "Symplify\\EasyCodingStandard\\Tests\\": "tests" + } + }, + "replace": { + "symfony/polyfill-php70": "*" + }, + "extra": { + "branch-alias": { + "dev-master": "7.3-dev" + } + }, + "minimum-stability": "dev", + "prefer-stable": true } diff --git a/packages/EasyCodingStandard/config/set/php_cs_fixer/php-cs-fixer-psr2.yaml b/packages/EasyCodingStandard/config/set/php_cs_fixer/php-cs-fixer-psr2.yaml index cb46d9388b5..6c1d69a2ba1 100644 --- a/packages/EasyCodingStandard/config/set/php_cs_fixer/php-cs-fixer-psr2.yaml +++ b/packages/EasyCodingStandard/config/set/php_cs_fixer/php-cs-fixer-psr2.yaml @@ -1,4 +1,4 @@ -# updated to PHP CS Fixer v2.11.0 +# updated to PHP CS Fixer v2.11.0 from https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/master/src/RuleSet.php services: # PSR1 diff --git a/packages/EasyCodingStandard/src/DependencyInjection/DelegatingLoaderFactory.php b/packages/EasyCodingStandard/src/DependencyInjection/DelegatingLoaderFactory.php index 6686c93f1af..593f2a499a9 100644 --- a/packages/EasyCodingStandard/src/DependencyInjection/DelegatingLoaderFactory.php +++ b/packages/EasyCodingStandard/src/DependencyInjection/DelegatingLoaderFactory.php @@ -19,7 +19,9 @@ public function createFromContainerBuilderAndKernel( ContainerBuilder $containerBuilder, KernelInterface $kernel ): DelegatingLoader { - return $this->createFromContainerBuilderAndFileLocator($containerBuilder, new FileLocator($kernel)); + $kernelFileLocator = new FileLocator($kernel); + + return $this->createFromContainerBuilderAndFileLocator($containerBuilder, $kernelFileLocator); } /** @@ -29,7 +31,8 @@ public function createContainerBuilderAndConfig( ContainerBuilder $containerBuilder, string $config ): DelegatingLoader { - $fileLocator = new SimpleFileLocator(dirname($config)); + $directory = dirname($config); + $fileLocator = new SimpleFileLocator($directory); return $this->createFromContainerBuilderAndFileLocator($containerBuilder, $fileLocator); } diff --git a/packages/EasyCodingStandard/src/HttpKernel/EasyCodingStandardKernel.php b/packages/EasyCodingStandard/src/HttpKernel/EasyCodingStandardKernel.php index acb90d386e4..78c076e95ac 100644 --- a/packages/EasyCodingStandard/src/HttpKernel/EasyCodingStandardKernel.php +++ b/packages/EasyCodingStandard/src/HttpKernel/EasyCodingStandardKernel.php @@ -105,6 +105,8 @@ protected function build(ContainerBuilder $containerBuilder): void */ protected function getContainerLoader(ContainerInterface $container): DelegatingLoader { - return (new DelegatingLoaderFactory())->createFromContainerBuilderAndKernel($container, $this); + $delegatingLoaderFactory = new DelegatingLoaderFactory(); + + return $delegatingLoaderFactory->createFromContainerBuilderAndKernel($container, $this); } } diff --git a/packages/EasyCodingStandard/src/Yaml/FileLoader/CheckerTolerantYamlFileLoader.php b/packages/EasyCodingStandard/src/Yaml/FileLoader/CheckerTolerantYamlFileLoader.php index 7b65d8a5195..2483bdd8679 100644 --- a/packages/EasyCodingStandard/src/Yaml/FileLoader/CheckerTolerantYamlFileLoader.php +++ b/packages/EasyCodingStandard/src/Yaml/FileLoader/CheckerTolerantYamlFileLoader.php @@ -36,8 +36,6 @@ public function __construct(ContainerBuilder $containerBuilder, FileLocatorInter */ protected function loadFile($file) { - var_dump($file); - /** @var mixed[]|null $configuration */ $configuration = parent::loadFile($file); if ($configuration === null) { diff --git a/phpstan.neon b/phpstan.neon index b9743f87539..570af8c5274 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -136,3 +136,5 @@ parameters: - '#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#' + - '#Parameter \#1 \$jsonContent of method Symplify\\EasyCodingStandard\\Compiler\\Packagist\\SymplifyStableVersionProvider\:\:loadContentJsonStringToArray\(\) expects string, string\|false given#' + - '#Method Symplify\\EasyCodingStandard\\Compiler\\Packagist\\SymplifyStableVersionProvider\:\:getLastKey\(\) should return string but returns int\|string\|null#'