Skip to content

Commit 967772b

Browse files
authored
[deprecation] Deprecate old symfony-legacy closure configuration (#25)
* update tempalte iwth levels * deprecate ECS config * nested
1 parent 5ae3d21 commit 967772b

6 files changed

Lines changed: 42 additions & 4 deletions

File tree

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
],
1414
"require": {
1515
"php": ">=8.4",
16-
"composer/pcre": "^3.3.2",
16+
"composer/pcre": "^3.4",
1717
"composer/xdebug-handler": "^3.0.5",
1818
"entropy/entropy": "^0.4",
1919
"friendsofphp/php-cs-fixer": "^3.95.5",
@@ -37,7 +37,7 @@
3737
"symplify/phpstan-rules": "^14.11",
3838
"symplify/vendor-patches": "^11.5",
3939
"tomasvotruba/class-leak": "^2.1.7",
40-
"tomasvotruba/type-coverage": "^2.1",
40+
"tomasvotruba/type-coverage": "^2.2",
4141
"tomasvotruba/unused-public": "^2.2",
4242
"tracy/tracy": "^2.12"
4343
},

phpstan.neon

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ parameters:
77
checkMissingCallableSignature: true
88

99
# symplify - see https://github.com/symplify/phpstan-rules#usage
10-
pathStrings: true
10+
symplify:
11+
pathStrings: true
1112

1213
paths:
1314
- packages

src/DependencyInjection/ServiceContainerFactory.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Symplify\EasyCodingStandard\DependencyInjection;
66

7+
use Closure;
78
use Entropy\Container\Container;
89
use PHP_CodeSniffer\Util\Tokens;
910
use PhpCsFixer\Differ\DifferInterface;
@@ -68,6 +69,18 @@ static function (Container $container): EasyCodingStandardStyle {
6869
$configClosure = require $configFile;
6970
Assert::isCallable($configClosure);
7071

72+
if ($configClosure instanceof Closure && ! defined('PHPUNIT_COMPOSER_INSTALL')) {
73+
/** @var SymfonyStyle $symfonyStyle */
74+
$symfonyStyle = $ecsConfig->make(SymfonyStyle::class);
75+
$symfonyStyle->warning(sprintf(
76+
'The "return function (ECSConfig $ecsConfig): void {}" config format is deprecated. Use "return ECSConfig::configure()" fluent API instead in "%s".',
77+
$configFile
78+
));
79+
80+
// give the user a moment to notice the deprecation warning
81+
sleep(5);
82+
}
83+
7184
$configClosure($ecsConfig);
7285
}
7386

templates/ecs.php.dist

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ return ECSConfig::configure()
99
->withPaths([
1010
__PATHS__
1111
])
12+
// include *.php files in the root directory
13+
->withRootFiles()
1214

1315
// add a single rule
1416
->withRules([
@@ -18,4 +20,9 @@ __PATHS__
1820
// add sets - group of rules, from easiest to more complex ones
1921
// uncomment one, apply one, commit, PR, merge and repeat
2022
__PREPARED_SETS__
21-
;
23+
24+
// ...but first: take it step by step
25+
->withSpacesLevel(0)
26+
->withArrayLevel(0)
27+
->withControlStructuresLevel(0)
28+
->withDocblockLevel(0);
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Symplify\EasyCodingStandard\Config\ECSConfig;
6+
7+
return static function (ECSConfig $ecsConfig): void {
8+
};

tests/DependencyInjection/ConfigurationFileTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,13 @@ public function testIncludeConfig(): void
3131
$sniffFileProcessor = $this->make(SniffFileProcessor::class);
3232
$this->assertCount(1, $sniffFileProcessor->getCheckers());
3333
}
34+
35+
public function testDeprecatedClosureConfig(): void
36+
{
37+
// the old closure config format is deprecated, but still loads
38+
$this->createContainerWithConfigs([__DIR__ . '/ConfigurationFileSource/deprecated-closure-config.php']);
39+
40+
$fixerFileProcessor = $this->make(FixerFileProcessor::class);
41+
$this->assertCount(0, $fixerFileProcessor->getCheckers());
42+
}
3443
}

0 commit comments

Comments
 (0)