diff --git a/bin/generate-php-cs-fixer-tests.php b/bin/generate-php-cs-fixer-tests.php
deleted file mode 100644
index 726f81ea0c..0000000000
--- a/bin/generate-php-cs-fixer-tests.php
+++ /dev/null
@@ -1,89 +0,0 @@
-getName();
-}
-
-// create withPhpCsFixerSets() method here
-$classMethod = new ClassMethod('withPhpCsFixerSets');
-$classMethod->flags = Modifiers::PUBLIC;
-$classMethod->returnType = new Name('self');
-
-foreach ($setNames as $setName) {
- // convert to PHP variable name
- $paramName = ltrim($setName, '@');
-
- $paramName = lowercaseUntilFirstLower($paramName);
- $paramName = str_replace(':r', 'R', $paramName);
- $paramName = str_replace(['.', '-', '_'], '', $paramName);
-
- // lowercase only the first uppercase letters
-
- $classMethod->params[] = new Param(
- new Variable($paramName),
- new ConstFetch(new Name('false')),
- new Identifier('bool')
- );
-
- $dynamicSetsPropertyFetch = new PropertyFetch(new Variable('this'), 'dynamicSets');
-
- $classMethod->stmts[] = new If_(new Variable($paramName), [
- 'stmts' => [
- new Expression(new Assign(new ArrayDimFetch($dynamicSetsPropertyFetch), new String_($setName))),
- ],
- ]);
-}
-
-function lowercaseUntilFirstLower($input): string
-{
- $output = '';
- $foundLower = false;
-
- for ($i = 0; $i < strlen((string) $input); $i++) {
- $char = $input[$i];
-
- if (! $foundLower && ctype_upper((string) $char)) {
- $output .= strtolower((string) $char);
- } else {
- $output .= $char;
- $foundLower = true;
- }
- }
-
- return $output;
-}
-
-// add dynamic set includes
-
-$classMethod->stmts[] = new Return_(new Variable('this'));
-
-$printerStandard = new Standard();
-echo $printerStandard->prettyPrint([$classMethod]);
diff --git a/build/target-repository/README.md b/build/target-repository/README.md
index 2a8fbf06b0..4706b19cce 100644
--- a/build/target-repository/README.md
+++ b/build/target-repository/README.md
@@ -131,20 +131,6 @@ Or enable everything at once with `->withPreparedSets(common: true)`.
-Do you want to include one of sets from [php-cs-fixer](https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/master/doc/ruleSets/index.rst)?
-
-You can:
-
-```php
-use Symplify\EasyCodingStandard\Config\ECSConfig;
-
-return ECSConfig::configure()
- ->withPaths([__DIR__ . '/src', __DIR__ . '/tests'])
- ->withPhpCsFixerSets(perCS20: true, doctrineAnnotation: true);
-```
-
-
-
### Gradual Adoption with Levels
Want to adopt a coding standard step by step instead of all at once? Use `with*Level()` methods to start from the safest rules and raise the level as your codebase catches up:
diff --git a/packages/coding-standard/src/Fixer/LineLength/LineLengthFixer.php b/packages/coding-standard/src/Fixer/LineLength/LineLengthFixer.php
index bdc211effb..699d662308 100644
--- a/packages/coding-standard/src/Fixer/LineLength/LineLengthFixer.php
+++ b/packages/coding-standard/src/Fixer/LineLength/LineLengthFixer.php
@@ -205,7 +205,7 @@ private function processFunctionOrArray(Tokens $tokens, int $position): void
}
// @todo is __construct() class method and is newline parma enabled? → skip it
- if ($this->standaloneLineConstructorParamFixer && $this->methodNameResolver->isMethodName(
+ if ($this->standaloneLineConstructorParamFixer instanceof StandaloneLineConstructorParamFixer && $this->methodNameResolver->isMethodName(
$tokens,
$position,
'__construct'
diff --git a/src/Config/ECSConfig.php b/src/Config/ECSConfig.php
index 0b140f8be1..22b0f04114 100644
--- a/src/Config/ECSConfig.php
+++ b/src/Config/ECSConfig.php
@@ -4,14 +4,14 @@
namespace Symplify\EasyCodingStandard\Config;
+use Entropy\Console\Output\OutputColorizer;
+use Entropy\Console\Output\OutputPrinter;
use Entropy\Container\Container;
use Override;
use PHP_CodeSniffer\Sniffs\Sniff;
use PhpCsFixer\Fixer\ConfigurableFixerInterface;
use PhpCsFixer\Fixer\FixerInterface;
use PhpCsFixer\Fixer\WhitespacesAwareFixerInterface;
-use PhpCsFixer\FixerFactory;
-use PhpCsFixer\RuleSet\RuleSet;
use PhpCsFixer\WhitespacesFixerConfig;
use Symplify\EasyCodingStandard\Configuration\ECSConfigBuilder;
use Symplify\EasyCodingStandard\DependencyInjection\CompilerPass\ConflictingCheckersCompilerPass;
@@ -201,27 +201,20 @@ public function reportingRealPath(bool $absolute = true): void
}
/**
- * @see https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/master/doc/ruleSets/index.rst
+ * @deprecated Loading PHP-CS-Fixer sets is deprecated. Use ->rule()/->ruleWithConfiguration() or prepared sets instead.
* @param string[] $setNames
*/
public function dynamicSets(array $setNames): void
{
- $fixerFactory = new FixerFactory();
- $fixerFactory->registerBuiltInFixers();
-
- $ruleSet = new RuleSet(array_fill_keys($setNames, true));
- $fixerFactory->useRuleSet($ruleSet);
-
- /** @var FixerInterface $fixer */
- foreach ($fixerFactory->getFixers() as $fixer) {
- $ruleConfiguration = $ruleSet->getRuleConfiguration($fixer->getName());
+ $outputPrinter = new OutputPrinter(new OutputColorizer());
+ $outputPrinter->warning(
+ 'The "dynamicSets()" method is deprecated. Use ->rule()/->ruleWithConfiguration() or prepared sets instead.'
+ );
- if ($ruleConfiguration === null) {
- $this->rule($fixer::class);
- } else {
- $this->ruleWithConfiguration($fixer::class, $ruleConfiguration);
- }
- }
+ trigger_error(
+ 'The "dynamicSets()" method is deprecated. Use ->rule()/->ruleWithConfiguration() or prepared sets instead.',
+ E_USER_DEPRECATED
+ );
}
public function import(string $setFilePath): void
diff --git a/src/Configuration/ECSConfigBuilder.php b/src/Configuration/ECSConfigBuilder.php
index 702ccea2bc..f695b4e98a 100644
--- a/src/Configuration/ECSConfigBuilder.php
+++ b/src/Configuration/ECSConfigBuilder.php
@@ -4,6 +4,8 @@
namespace Symplify\EasyCodingStandard\Configuration;
+use Entropy\Console\Output\OutputColorizer;
+use Entropy\Console\Output\OutputPrinter;
use PHP_CodeSniffer\Sniffs\Sniff;
use PHP_CodeSniffer\Standards\Generic\Sniffs\Files\EndFileNewlineSniff as GenericEndFileNewlineSniff;
use PHP_CodeSniffer\Standards\Generic\Sniffs\Files\EndFileNoNewlineSniff;
@@ -46,11 +48,6 @@ final class ECSConfigBuilder
*/
private array $sets = [];
- /**
- * @var string[]
- */
- private array $dynamicSets = [];
-
/**
* @var array
*/
@@ -132,10 +129,6 @@ public function __invoke(ECSConfig $ecsConfig): void
$ecsConfig->sets($this->sets);
}
- if ($this->dynamicSets !== []) {
- $ecsConfig->dynamicSets($this->dynamicSets);
- }
-
if ($this->paths !== []) {
$ecsConfig->paths($this->paths);
}
@@ -351,307 +344,15 @@ public function withPreparedSets(
return $this;
}
- public function withPhpCsFixerSets(
- bool $doctrineAnnotation = false,
- bool $per = false,
- bool $perCS = false,
- bool $perCS10 = false,
- bool $perCS10Risky = false,
- bool $perCS20 = false,
- bool $perCS20Risky = false,
- bool $perCSRisky = false,
- bool $perRisky = false,
- bool $php54Migration = false,
- bool $php56MigrationRisky = false,
- bool $php70Migration = false,
- bool $php70MigrationRisky = false,
- bool $php71Migration = false,
- bool $php71MigrationRisky = false,
- bool $php73Migration = false,
- bool $php74Migration = false,
- bool $php74MigrationRisky = false,
- bool $php80Migration = false,
- bool $php80MigrationRisky = false,
- bool $php81Migration = false,
- bool $php82Migration = false,
- bool $php83Migration = false,
- bool $php84Migration = false,
- bool $phpunit30MigrationRisky = false,
- bool $phpunit32MigrationRisky = false,
- bool $phpunit35MigrationRisky = false,
- bool $phpunit43MigrationRisky = false,
- bool $phpunit48MigrationRisky = false,
- bool $phpunit50MigrationRisky = false,
- bool $phpunit52MigrationRisky = false,
- bool $phpunit54MigrationRisky = false,
- bool $phpunit55MigrationRisky = false,
- bool $phpunit56MigrationRisky = false,
- bool $phpunit57MigrationRisky = false,
- bool $phpunit60MigrationRisky = false,
- bool $phpunit75MigrationRisky = false,
- bool $phpunit84MigrationRisky = false,
- bool $phpunit100MigrationRisky = false,
- bool $psr1 = false,
- bool $psr2 = false,
- bool $psr12 = false,
- bool $psr12Risky = false,
- bool $phpCsFixer = false,
- bool $phpCsFixerRisky = false,
- bool $symfony = false,
- bool $symfonyRisky = false,
- bool $perCS30 = false,
- bool $perCS30Risky = false,
- bool $php81MigrationRisky = false,
- bool $php82MigrationRisky = false,
- bool $php83MigrationRisky = false,
- bool $php84MigrationRisky = false,
- bool $php85Migration = false,
- bool $php85MigrationRisky = false,
- bool $auto = false,
- bool $autoRisky = false,
- bool $autoPHPMigration = false,
- bool $autoPHPMigrationRisky = false,
- bool $autoPHPUnitMigrationRisky = false,
- ): self {
- if ($doctrineAnnotation) {
- $this->dynamicSets[] = '@DoctrineAnnotation';
- }
-
- if ($per) {
- $this->dynamicSets[] = '@PER';
- }
-
- if ($perCS) {
- $this->dynamicSets[] = '@PER-CS';
- }
-
- if ($perCS10) {
- $this->dynamicSets[] = '@PER-CS1x0';
- }
-
- if ($perCS10Risky) {
- $this->dynamicSets[] = '@PER-CS1x0:risky';
- }
-
- if ($perCS20) {
- $this->dynamicSets[] = '@PER-CS2x0';
- }
-
- if ($perCS20Risky) {
- $this->dynamicSets[] = '@PER-CS2x0:risky';
- }
-
- if ($perCS30) {
- $this->dynamicSets[] = '@PER-CS3x0';
- }
-
- if ($perCS30Risky) {
- $this->dynamicSets[] = '@PER-CS3x0:risky';
- }
-
- if ($perCSRisky) {
- $this->dynamicSets[] = '@PER-CS:risky';
- }
-
- if ($perRisky) {
- $this->dynamicSets[] = '@PER:risky';
- }
-
- if ($php54Migration) {
- $this->dynamicSets[] = '@PHP5x4Migration';
- }
-
- if ($php56MigrationRisky) {
- $this->dynamicSets[] = '@PHP5x6Migration:risky';
- }
-
- if ($php70Migration) {
- $this->dynamicSets[] = '@PHP7x0Migration';
- }
-
- if ($php70MigrationRisky) {
- $this->dynamicSets[] = '@PHP7x0Migration:risky';
- }
-
- if ($php71Migration) {
- $this->dynamicSets[] = '@PHP7x1Migration';
- }
-
- if ($php71MigrationRisky) {
- $this->dynamicSets[] = '@PHP7x1Migration:risky';
- }
-
- if ($php73Migration) {
- $this->dynamicSets[] = '@PHP7x3Migration';
- }
-
- if ($php74Migration) {
- $this->dynamicSets[] = '@PHP7x4Migration';
- }
-
- if ($php74MigrationRisky) {
- $this->dynamicSets[] = '@PHP7x4Migration:risky';
- }
-
- if ($php80Migration) {
- $this->dynamicSets[] = '@PHP8x0Migration';
- }
-
- if ($php80MigrationRisky) {
- $this->dynamicSets[] = '@PHP8x0Migration:risky';
- }
-
- if ($php81Migration) {
- $this->dynamicSets[] = '@PHP8x1Migration';
- }
-
- if ($php81MigrationRisky) {
- $this->dynamicSets[] = '@PHP8x1Migration:risky';
- }
-
- if ($php82Migration) {
- $this->dynamicSets[] = '@PHP8x2Migration';
- }
-
- if ($php82MigrationRisky) {
- $this->dynamicSets[] = '@PHP8x2Migration:risky';
- }
-
- if ($php83Migration) {
- $this->dynamicSets[] = '@PHP8x3Migration';
- }
-
- if ($php83MigrationRisky) {
- $this->dynamicSets[] = '@PHP8x3Migration:risky';
- }
-
- if ($php84Migration) {
- $this->dynamicSets[] = '@PHP8x4Migration';
- }
-
- if ($php84MigrationRisky) {
- $this->dynamicSets[] = '@PHP8x4Migration:risky';
- }
-
- if ($php85Migration) {
- $this->dynamicSets[] = '@PHP8x5Migration';
- }
-
- if ($php85MigrationRisky) {
- $this->dynamicSets[] = '@PHP8x5Migration:risky';
- }
-
- if ($phpunit30MigrationRisky) {
- $this->dynamicSets[] = '@PHPUnit3x0Migration:risky';
- }
-
- if ($phpunit32MigrationRisky) {
- $this->dynamicSets[] = '@PHPUnit3x2Migration:risky';
- }
-
- if ($phpunit35MigrationRisky) {
- $this->dynamicSets[] = '@PHPUnit3x5Migration:risky';
- }
-
- if ($phpunit43MigrationRisky) {
- $this->dynamicSets[] = '@PHPUnit4x3Migration:risky';
- }
-
- if ($phpunit48MigrationRisky) {
- $this->dynamicSets[] = '@PHPUnit4x8Migration:risky';
- }
-
- if ($phpunit50MigrationRisky) {
- $this->dynamicSets[] = '@PHPUnit5x0Migration:risky';
- }
-
- if ($phpunit52MigrationRisky) {
- $this->dynamicSets[] = '@PHPUnit5x2Migration:risky';
- }
-
- if ($phpunit54MigrationRisky) {
- $this->dynamicSets[] = '@PHPUnit5x4Migration:risky';
- }
-
- if ($phpunit55MigrationRisky) {
- $this->dynamicSets[] = '@PHPUnit5x5Migration:risky';
- }
-
- if ($phpunit56MigrationRisky) {
- $this->dynamicSets[] = '@PHPUnit5x6Migration:risky';
- }
-
- if ($phpunit57MigrationRisky) {
- $this->dynamicSets[] = '@PHPUnit5x7Migration:risky';
- }
-
- if ($phpunit60MigrationRisky) {
- $this->dynamicSets[] = '@PHPUnit6x0Migration:risky';
- }
-
- if ($phpunit75MigrationRisky) {
- $this->dynamicSets[] = '@PHPUnit7x5Migration:risky';
- }
-
- if ($phpunit84MigrationRisky) {
- $this->dynamicSets[] = '@PHPUnit8x4Migration:risky';
- }
-
- if ($phpunit100MigrationRisky) {
- $this->dynamicSets[] = '@PHPUnit10x0Migration:risky';
- }
-
- if ($psr1) {
- $this->dynamicSets[] = '@PSR1';
- }
-
- if ($psr2) {
- $this->dynamicSets[] = '@PSR2';
- }
-
- if ($psr12) {
- $this->dynamicSets[] = '@PSR12';
- }
-
- if ($psr12Risky) {
- $this->dynamicSets[] = '@PSR12:risky';
- }
-
- if ($phpCsFixer) {
- $this->dynamicSets[] = '@PhpCsFixer';
- }
-
- if ($phpCsFixerRisky) {
- $this->dynamicSets[] = '@PhpCsFixer:risky';
- }
-
- if ($symfony) {
- $this->dynamicSets[] = '@Symfony';
- }
-
- if ($symfonyRisky) {
- $this->dynamicSets[] = '@Symfony:risky';
- }
-
- if ($auto) {
- $this->dynamicSets[] = '@auto';
- }
-
- if ($autoRisky) {
- $this->dynamicSets[] = '@auto:risky';
- }
-
- if ($autoPHPMigration) {
- $this->dynamicSets[] = '@autoPHPMigration';
- }
-
- if ($autoPHPMigrationRisky) {
- $this->dynamicSets[] = '@autoPHPMigration:risky';
- }
-
- if ($autoPHPUnitMigrationRisky) {
- $this->dynamicSets[] = '@autoPHPUnitMigration:risky';
- }
+ /**
+ * @deprecated Loading PHP-CS-Fixer sets is deprecated. Use ->withPreparedSets() or ->withSets() with the prepared sets instead.
+ */
+ public function withPhpCsFixerSets(): self
+ {
+ $outputPrinter = new OutputPrinter(new OutputColorizer());
+ $outputPrinter->warning(
+ 'The "withPhpCsFixerSets()" method is deprecated. Use ->withPreparedSets() or ->withSets() with prepared sets instead.'
+ );
return $this;
}
diff --git a/tests/FixerRunner/DependencyInjection/FixerServiceRegistrationTest.php b/tests/FixerRunner/DependencyInjection/FixerServiceRegistrationTest.php
index 9c51fefa64..abcca51e7d 100644
--- a/tests/FixerRunner/DependencyInjection/FixerServiceRegistrationTest.php
+++ b/tests/FixerRunner/DependencyInjection/FixerServiceRegistrationTest.php
@@ -4,11 +4,8 @@
namespace Symplify\EasyCodingStandard\Tests\FixerRunner\DependencyInjection;
-use Iterator;
use PhpCsFixer\Fixer\ArrayNotation\ArraySyntaxFixer;
use PhpCsFixer\Fixer\ClassNotation\VisibilityRequiredFixer;
-use PhpCsFixer\Fixer\Import\OrderedImportsFixer;
-use PHPUnit\Framework\Attributes\DataProvider;
use Symplify\EasyCodingStandard\FixerRunner\Application\FixerFileProcessor;
use Symplify\EasyCodingStandard\Testing\PHPUnit\AbstractTestCase;
use Symplify\EasyCodingStandard\Utils\PrivatesAccessorHelper;
@@ -46,67 +43,4 @@ public function test(): void
'elements' => ['property'],
], $visibilityRequiredConfiguration);
}
-
- /**
- * See https://github.com/easy-coding-standard/easy-coding-standard/discussions/198
- *
- * @param array{
- * case_sensitive: bool,
- * imports_order: list|null,
- * sort_algorithm: string,
- * } $expectedConfiguration
- */
- #[DataProvider('provideRuleOverrideInSetData')]
- public function testRuleOverrideInSet(string $filename, array $expectedConfiguration): void
- {
- $this->createContainerWithConfigs([__DIR__ . '/config/test-rule-override-in-set/' . $filename]);
- $fixerFileProcessor = $this->make(FixerFileProcessor::class);
-
- $checkers = $fixerFileProcessor->getCheckers();
- $orderedImportsFixerInstances = [];
-
- foreach ($checkers as $checker) {
- if ($checker instanceof OrderedImportsFixer) {
- $orderedImportsFixerInstances[] = $checker;
- }
- }
-
- $this->assertCount(2, $orderedImportsFixerInstances);
-
- foreach ($orderedImportsFixerInstances as $orderedImportFixerInstance) {
- $configuration = PrivatesAccessorHelper::getPropertyValue($orderedImportFixerInstance, 'configuration');
-
- $this->assertSame($expectedConfiguration, $configuration);
- }
- }
-
- public static function provideRuleOverrideInSetData(): Iterator
- {
- yield [
- 'with-rules.php',
- [
- 'case_sensitive' => false,
- 'imports_order' => null,
- 'sort_algorithm' => OrderedImportsFixer::SORT_ALPHA,
- ],
- ];
-
- yield [
- 'with-configured-rule.php',
- [
- 'case_sensitive' => true,
- 'imports_order' => ['const', 'class', 'function'],
- 'sort_algorithm' => 'alpha',
- ],
- ];
-
- yield [
- 'with-configured-rule-and-empty-config.php',
- [
- 'case_sensitive' => false,
- 'imports_order' => null,
- 'sort_algorithm' => OrderedImportsFixer::SORT_ALPHA,
- ],
- ];
- }
}
diff --git a/tests/FixerRunner/DependencyInjection/config/test-rule-override-in-set/with-configured-rule-and-empty-config.php b/tests/FixerRunner/DependencyInjection/config/test-rule-override-in-set/with-configured-rule-and-empty-config.php
deleted file mode 100644
index 52c7159021..0000000000
--- a/tests/FixerRunner/DependencyInjection/config/test-rule-override-in-set/with-configured-rule-and-empty-config.php
+++ /dev/null
@@ -1,10 +0,0 @@
-withPhpCsFixerSets(perCS: true)
- ->withConfiguredRule(OrderedImportsFixer::class, []);
diff --git a/tests/FixerRunner/DependencyInjection/config/test-rule-override-in-set/with-configured-rule.php b/tests/FixerRunner/DependencyInjection/config/test-rule-override-in-set/with-configured-rule.php
deleted file mode 100644
index 9d4efe364b..0000000000
--- a/tests/FixerRunner/DependencyInjection/config/test-rule-override-in-set/with-configured-rule.php
+++ /dev/null
@@ -1,14 +0,0 @@
-withPhpCsFixerSets(perCS: true)
- ->withConfiguredRule(OrderedImportsFixer::class, [
- 'case_sensitive' => true,
- 'imports_order' => ['const', 'class', 'function'],
- 'sort_algorithm' => 'alpha',
- ]);
diff --git a/tests/FixerRunner/DependencyInjection/config/test-rule-override-in-set/with-rules.php b/tests/FixerRunner/DependencyInjection/config/test-rule-override-in-set/with-rules.php
deleted file mode 100644
index b92c19fe3b..0000000000
--- a/tests/FixerRunner/DependencyInjection/config/test-rule-override-in-set/with-rules.php
+++ /dev/null
@@ -1,10 +0,0 @@
-withPhpCsFixerSets(perCS: true)
- ->withRules([OrderedImportsFixer::class]);