diff --git a/composer.json b/composer.json index e5aa1c444c..e11839c850 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,7 @@ ], "require": { "php": ">=8.4", - "composer/pcre": "^3.3.2", + "composer/pcre": "^3.4", "composer/xdebug-handler": "^3.0.5", "entropy/entropy": "^0.4", "friendsofphp/php-cs-fixer": "^3.95.5", @@ -37,7 +37,7 @@ "symplify/phpstan-rules": "^14.11", "symplify/vendor-patches": "^11.5", "tomasvotruba/class-leak": "^2.1.7", - "tomasvotruba/type-coverage": "^2.1", + "tomasvotruba/type-coverage": "^2.2", "tomasvotruba/unused-public": "^2.2", "tracy/tracy": "^2.12" }, diff --git a/phpstan.neon b/phpstan.neon index ace8e7cdc5..917a25e542 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -7,7 +7,8 @@ parameters: checkMissingCallableSignature: true # symplify - see https://github.com/symplify/phpstan-rules#usage - pathStrings: true + symplify: + pathStrings: true paths: - packages diff --git a/src/DependencyInjection/ServiceContainerFactory.php b/src/DependencyInjection/ServiceContainerFactory.php index 3286a8822b..606431bb8e 100644 --- a/src/DependencyInjection/ServiceContainerFactory.php +++ b/src/DependencyInjection/ServiceContainerFactory.php @@ -4,6 +4,7 @@ namespace Symplify\EasyCodingStandard\DependencyInjection; +use Closure; use Entropy\Container\Container; use PHP_CodeSniffer\Util\Tokens; use PhpCsFixer\Differ\DifferInterface; @@ -68,6 +69,18 @@ static function (Container $container): EasyCodingStandardStyle { $configClosure = require $configFile; Assert::isCallable($configClosure); + if ($configClosure instanceof Closure && ! defined('PHPUNIT_COMPOSER_INSTALL')) { + /** @var SymfonyStyle $symfonyStyle */ + $symfonyStyle = $ecsConfig->make(SymfonyStyle::class); + $symfonyStyle->warning(sprintf( + 'The "return function (ECSConfig $ecsConfig): void {}" config format is deprecated. Use "return ECSConfig::configure()" fluent API instead in "%s".', + $configFile + )); + + // give the user a moment to notice the deprecation warning + sleep(5); + } + $configClosure($ecsConfig); } diff --git a/templates/ecs.php.dist b/templates/ecs.php.dist index f6f57eb6d5..a479fe7bed 100644 --- a/templates/ecs.php.dist +++ b/templates/ecs.php.dist @@ -9,6 +9,8 @@ return ECSConfig::configure() ->withPaths([ __PATHS__ ]) + // include *.php files in the root directory + ->withRootFiles() // add a single rule ->withRules([ @@ -18,4 +20,9 @@ __PATHS__ // add sets - group of rules, from easiest to more complex ones // uncomment one, apply one, commit, PR, merge and repeat __PREPARED_SETS__ - ; + + // ...but first: take it step by step + ->withSpacesLevel(0) + ->withArrayLevel(0) + ->withControlStructuresLevel(0) + ->withDocblockLevel(0); diff --git a/tests/DependencyInjection/ConfigurationFileSource/deprecated-closure-config.php b/tests/DependencyInjection/ConfigurationFileSource/deprecated-closure-config.php new file mode 100644 index 0000000000..9500565ce3 --- /dev/null +++ b/tests/DependencyInjection/ConfigurationFileSource/deprecated-closure-config.php @@ -0,0 +1,8 @@ +make(SniffFileProcessor::class); $this->assertCount(1, $sniffFileProcessor->getCheckers()); } + + public function testDeprecatedClosureConfig(): void + { + // the old closure config format is deprecated, but still loads + $this->createContainerWithConfigs([__DIR__ . '/ConfigurationFileSource/deprecated-closure-config.php']); + + $fixerFileProcessor = $this->make(FixerFileProcessor::class); + $this->assertCount(0, $fixerFileProcessor->getCheckers()); + } }