symplify/easy-coding-standard
Easy Coding Standard (ECS) makes PHP coding standards effortless on PHP 7.2–8.5. Fast parallel runs, supports PHP_CodeSniffer and PHP-CS-Fixer, uses prepared rule sets, generates ecs.php config on first run, and can check and auto-fix code with --fix.
StandaloneLineSymfonyAttributeParamFixerReplaces the str_contains($name, 'Symfony') heuristic with an explicit allowlist of 17 Symfony attribute classes (SYMFONY_ATTRIBUTE_CLASSES). Third-party attributes whose FQCN merely contains Symfony (e.g. App\Symfony\...) are no longer reformatted.
-#[\Symfony\Component\Console\Attribute\AsCommand(name: 'app:some', description: 'Some description')]
+#[\Symfony\Component\Console\Attribute\AsCommand(
+ name: 'app:some',
+ description: 'Some description'
+)]
pull_request trigger from version_command workflowThe job smoke-tests the published Packagist artifact, so on PRs it installed the already-published package, never the PR code — pure slow noise. push (main + tags) and weekly schedule already cover it.
StandaloneLineSymfonyAttributeParamFixer + standaloneLine setBreaks each argument of a Symfony attribute onto its own line. New opt-in standaloneLine set groups the standalone-line rules.
-#[\Symfony\Component\Console\Attribute\AsCommand(name: 'mautic:entity:import', description: 'Import entity data from a ZIP file.')]
+#[\Symfony\Component\Console\Attribute\AsCommand(
+ name: 'mautic:entity:import',
+ description: 'Import entity data from a ZIP file.'
+)]
$ecsConfig->withPreparedSets(standaloneLine: true);
// or
$ecsConfig->withSets([SetList::STANDALONE_LINE]);
Now resolves short names against use imports, not just fully-qualified names.
use Symfony\Component\Console\Attribute\AsCommand;
-#[AsCommand(name: 'app:some', description: 'Some description')]
+#[AsCommand(
+ name: 'app:some',
+ description: 'Some description'
+)]
s in method-name duplicate description-/**
- * Contacts a user.
*
* [@return](https://github.com/return) object
*/
public function contactUser()
scoper.php for FinalInternalClassFixer (#24)Prefixed build no longer mangles the exclude entity names:
-'exclude' => ['final', 'Entity', 'ECSPrefix202607\ORM\Entity', ...]
+'exclude' => ['final', 'Entity', 'ORM\Entity', ...]
Locks StandaloneLinePromotedPropertyFixer splitting private readonly promoted props.
StandaloneLinePlainConstructorParamFixer skips ≤3 paramsOnly splits constructors with 4+ params. Short lists stay on one line. Default-value tokens ([1, 2], new Foo(1)) don't inflate the count.
StandaloneLinePlainConstructorParamFixer (spaces set)Covers the gap: constructors with plain params and no promoted properties.
-public function __construct(CorePermissions $security, Translator $translator, RouterInterface $router, FormFactoryInterface $formFactory)
+public function __construct(
+ CorePermissions $security,
+ Translator $translator,
+ RouterInterface $router,
+ FormFactoryInterface $formFactory
+)
Locks StandaloneLinePromotedPropertyFixer splitting all params even when only one is promoted.
public function __construct(
- CorePermissions $security, Translator $translator, RouterInterface $router,
+ CorePermissions $security,
+ Translator $translator,
+ RouterInterface $router,
private LeadModel $leadModel,
) {
}
StandaloneLineRequiredParamFixer (spaces set)Public methods marked #[Required] / [@required](https://github.com/required) are DI points; one param per line keeps diffs to the single changed dependency.
#[Required]
-public function autowireDependencies(FormModel $formModel, SubmissionModel $submissionModel): void
+public function autowireDependencies(
+ FormModel $formModel,
+ SubmissionModel $submissionModel
+): void
-/**
- * Get the API helper.
- *
+/**
* [@return](https://github.com/return) object
*/
public function getApiHelper()
Drops a/an/the (word-boundary) before comparing description to method name.
vendor/bin/ecs src tests
--config option placed before the command name# before
$ ecs --config=ecs.php
Run failed: Unknown option: "--config=ecs.php"
# after
$ ecs --config=ecs.php # loads ecs.php and checks normally
Regression from the symfony/console → entropy migration. Default check command is now injected when the first arg is an option.
AddMissingVarNameFixer for property assignments-/** [@var](https://github.com/var) int $this */
+/** [@var](https://github.com/var) int */
$this->value = 1000;
Skipped when the variable is followed by ->.
TypeToVarTagFixerFlips [@type](https://github.com/type) doc tag into [@var](https://github.com/var), upgrading single-asterisk inline comments to real doc blocks.
-/* [@type](https://github.com/type) \Mautic\ReportBundle\Model\ReportModel $model */
+/** [@var](https://github.com/var) \Mautic\ReportBundle\Model\ReportModel $model */
$model = ...;
MergeDocBlockStartFixerFixes docblocks opened with /* instead of /** and strips empty *-only lines.
-/*
- *
- * [@return](https://github.com/return) $this
- */
+/**
+ * [@return](https://github.com/return) $this
+ */
RemoveEventSubscriberDescriptionFixerRemoves redundant subscriber-method docblocks that just repeat the method name + "event".
-/**
- * Delete lead event
- */
public function onLeadDelete(LeadEvent $event): bool
RemoveMethodNameDuplicateDescriptionFixer now drops * Get results. above setResults() (get/set mix-up carries no info).
RemoveDeadParamFixer for anonymous functions-/**
- * [@param](https://github.com/param) $mappedFields
- * [@param](https://github.com/param) $fieldType
- */
$cleanup = function (array &$mappedFields, string $fieldType) {
};
Scope PHPStan ignores for T_OPEN_CURLY_BRACKET (PHP_CodeSniffer constant) across environments.
Preload path fix after the console / dependency migration.
common sets + LevelsTwo new sets (casing, cleanup) and 40 more mature, non-PSR-12 rules wired into the gradual-adoption Levels.
-STRLEN($name); // NativeFunctionCasing
+strlen($name);
-$a = [ ]; // NoWhitespaceInEmptyArray
+$a = [];
-/** [@return](https://github.com/return) integer */ // PhpdocScalar
+/** [@return](https://github.com/return) int */
-$x = isset($a) ? $a : $b; // TernaryToNullCoalescing
+$x = $a ?? $b;
New [@api](https://github.com/api) consts SetList::CASING, SetList::CLEANUP; withPreparedSets(casing:, cleanup:).
symplify set, remove phpunit + strict setssymplify soft-deprecated (rules now in common under clearer names). phpunit and strict removed — dangerous without context, use Rector instead.
return ECSConfig::configure()
->withPreparedSets(
common: true,
- symplify: true,
- phpunit: true,
- strict: true,
);
FixTagTypoFixerFixes plural doc-block tag typos ([@returns](https://github.com/returns)→[@return](https://github.com/return), [@params](https://github.com/params)→[@param](https://github.com/param), [@vars](https://github.com/vars)→[@var](https://github.com/var)), incl. psalm-/phpstan- prefixes.
AddMissingVarNameFixer for intersection types-/** [@var](https://github.com/var) MockObject&AbstractIntegration */
+/** [@var](https://github.com/var) MockObject&AbstractIntegration $integration */
$integration = $this->getMockBuilder(AbstractIntegration::class);
SwitchedTypeAndNameFixer for generics with commas-[@param](https://github.com/param) $submittedArray array<int, string>
+[@param](https://github.com/param) array<int, string> $submittedArray
[@param](https://github.com/param) comment text mistaken as switched type[@param](https://github.com/param) $extra Can be used by ... no longer reordered — trailing words are a description, not a type.
RemoveMethodNameDuplicateDescriptionFixer now strips * Set name. (trailing ./!) above setName().
symfony/console, migrate console layer to entropy/entropy (#27)symplify/easy-parallel for fewer deps (#28)symfony-legacy closure configurationThe legacy closure-based Symfony config is deprecated. Use the fluent API instead:
return ECSConfig::configure()
->withPreparedSets(common: true);
RemoveDeadVarThisFixerRemoves pointless [@var](https://github.com/var) $this docblocks above $this calls — they add noise and never help type inference. Added to the docblock level.
function someFunction()
{
- /** [@var](https://github.com/var) SomeType $this */
$this->run();
}
AddMissingVarNameFixer for array item typesThe fixer now correctly appends the variable name when the [@var](https://github.com/var) type is an array shape like int[]:
function arrayItems()
{
- /** [@var](https://github.com/var) int[] */
+ /** [@var](https://github.com/var) int[] $values */
$values = [1000];
}
The headline of this release: ECS is now a single package. The symplify/coding-standard fixers moved in-tree, and the Laravel container dependency is gone. No breaking changes for users — the Symplify\CodingStandard\Fixer\* class names are unchanged.
If you previously required symplify/coding-standard directly, drop it — it now ships inside ECS:
composer remove symplify/coding-standard --dev
composer require symplify/easy-coding-standard:^13.2 --dev
Your ecs.php needs no changes: the Symplify\CodingStandard\Fixer\* class names are unchanged. If you only ever required symplify/easy-coding-standard, a plain composer update symplify/easy-coding-standard is all you need.
symplify/coding-standard merged into ECS (#19)The 26 custom Symplify fixers ECS has always relied on now live directly in this repository under packages/coding-standard/. ECS could never run without them, and many prepared sets are tightly coupled to them — so maintaining two repos added friction for no benefit.
What this means for you:
One package instead of two. composer require symplify/easy-coding-standard --dev no longer pulls in a separate symplify/coding-standard.
Class names are unchanged — your existing ecs.php keeps working as-is:
// ecs.php — still valid, no change needed
use Symplify\EasyCodingStandard\Config\ECSConfig;
use Symplify\CodingStandard\Fixer\LineLength\LineLengthFixer;
return ECSConfig::configure()
->withRules([LineLengthFixer::class]);
->withPreparedSets(symplify: true);
withDocblockLevel() now goes much deeper (#19)Because the Symplify commenting fixers now ship in-tree, the gradual docblock level gained 11 new rules (24 total). You opt in one level per PR, safest first:
// ecs.php
use Symplify\EasyCodingStandard\Config\ECSConfig;
return ECSConfig::configure()
->withDocblockLevel(5); // ramp up one level at a time
New rules now reachable through the level include inline [@var](https://github.com/var) normalization (DoubleAsteriskInlineVarFixer, SingleLineInlineVarDocBlockFixer, AddMissingVarNameFixer), [@param](https://github.com/param) fixes (AddMissingParamNameFixer, FixParamNameTypoFixer, RemoveParamNameReferenceFixer, RemoveDeadParamFixer), and superfluous-name removal (RemoveSuperfluousReturnNameFixer, RemoveSuperfluousVarNameFixer).
illuminate/container replaced with entropy/entropy (#17)ECS's DI container no longer extends Illuminate's. ECSConfig now extends Entropy\Container\Container.
What this means for you:
illuminate/container and its bundled patch (patches/illuminate-container-container-php.patch) are gone.symfony/console stays — it's still a transitive dependency of PHP-CS-Fixer and easy-parallel, so it can't be dropped.This is an internal change. If you only use the public
ECSConfig::configure()->with...()API, nothing changes for you.
Full Changelog: https://github.com/easy-coding-standard/easy-coding-standard/compare/12.6.2...13.0.0
Full Changelog: https://github.com/easy-coding-standard/easy-coding-standard/compare/12.6.1...12.6.2
Full Changelog: https://github.com/easy-coding-standard/easy-coding-standard/compare/12.5.24...12.6.0
Full Changelog: https://github.com/easy-coding-standard/easy-coding-standard/compare/12.5.21...12.5.23
Full Changelog: https://github.com/easy-coding-standard/easy-coding-standard/compare/12.5.18...12.5.20
test Script by @Kenneth-Sills in https://github.com/easy-coding-standard/easy-coding-standard/pull/227Full Changelog: https://github.com/easy-coding-standard/easy-coding-standard/compare/12.5.6...12.5.8
Full Changelog: https://github.com/easy-coding-standard/easy-coding-standard/compare/12.5.4...12.5.5
Full Changelog: https://github.com/easy-coding-standard/easy-coding-standard/compare/12.2.0...12.2.1
--no-diffs CLI Option (#195), thanks @staabmEasyCodingStandardStyle->isDebug() (#194), thanks @staabmecs.phpRunning ECS on Symfony project can create conflict with native ContainerConfigurator. To avoid that, we introduce a new config, that is fully scoped and isolated within ECS.
Another big advantage is new configuration methods with validation and autocomplete right in your ide :+1:
Read more in https://tomasvotruba.com/blog/new-in-ecs-simpler-config/
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\EasyCodingStandard\ValueObject\Option;
// ups, possible conflict with ContainerConfigurator
return static function (ContainerConfigurator $containerConfigurator): void {
$parameters = $containerConfigurator->parameters();
// too verbose params, constants and possible typo in param value
$parameters->set(Option::PATHS, [[ // ups, "[[" typo
__DIR__ . '/src/',
]]);
$services = $containerConfigurator->services();
$services->set(ArraySyntaxFixer::class);
};
use Symplify\EasyCodingStandard\Config\ECSConfig;
use Symplify\EasyCodingStandard\ValueObject\Set\SetList;
return static function (ECSConfig $ecsConfig): void {
$ecsConfig->paths([
__DIR__ . '/src',
]);
$ecsConfig->rule(ArraySyntaxFixer::class);
$ecsConfig->sets([SetList::PSR_12]);
};
Do you have multi-core CPUs? ECS can run in X parallel threads, where X is number of your threads. E.g. with laptop with AMD Ryzen 4750U it is 16.
That means 1600 % faster run with same amount of analysed files. Did you code base took 16 minutes to fix? Now it's 1 minute.
This feature is:
Try it:
// ecs.php
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\EasyCodingStandard\ValueObject\Option;
return static function (ContainerConfigurator $containerConfigurator): void {
$parameters = $containerConfigurator->parameters();
$parameters->set(Option::PARALLEL, true);
};
And that's it :wink:
The parallel run is heavily based on @phpstan parallel run - thanks to Ondřej Mirtes for inspiration :pray:
Since 9.3.3, the package is downgraded to PHP 7.1 and scoped. The former package https://github.com/symplify/easy-coding-standard-prefixed is deprecated and replaced by symplify/easy-coding-standard should be used instead.
Read more in standalone post https://tomasvotruba.com/blog/introducing-ecs-prefixed-and-downgraded-to-php-71
How can I help you explore Laravel packages today?