百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
C

coding-standard

> 编程语言
开源

[已过时] 使用包含此集合以及更多新规则的 ECS

381 stars0 点赞0 次浏览
访问官网GitHub

工具介绍

[已过时] 使用包含此集合以及更多新规则的 ECS

Coding Standard

[!WARNING] This package is deprecated. Use Easy Coding Standard (ECS) instead, where these rules and coding standard work out of the box—no extra setup needed.

Coding standard rules for clean, consistent, and readable PHP code. No configuration needed—just install and let it handle the rest.

They run best with ECS.

Install

bash
composer require symplify/coding-standard symplify/easy-coding-standard --dev
  1. Register in ecs.php config:
php
 # ecs.php
 use Symplify\EasyCodingStandard\Config\ECSConfig;

 return ECSConfig::configure()
    ->withPreparedSets(symplify: true);
  1. And run:
bash
# dry-run without changes
vendor/bin/ecs

# apply changes
vendor/bin/ecs --fix

23 Rules to Keep Your Code Clean

ArrayListItemNewlineFixer

Indexed PHP array item has to have one line per item

  • class: Symplify\CodingStandard\Fixer\ArrayNotation\ArrayListItemNewlineFixer
diff
-$value = ['simple' => 1, 'easy' => 2];
+$value = ['simple' => 1,
+'easy' => 2];

ArrayOpenerAndCloserNewlineFixer

Indexed PHP array opener [ and closer ] must be on own line

  • class: Symplify\CodingStandard\Fixer\ArrayNotation\ArrayOpenerAndCloserNewlineFixer
diff
-$items = [1 => 'Hey'];
+$items = [
+1 => 'Hey'
+];

BlankLineAfterStrictTypesFixer

Strict type declaration has to be followed by empty line

  • class: Symplify\CodingStandard\Fixer\Strict\BlankLineAfterStrictTypesFixer
diff
 declare(strict_types=1);
+
 namespace App;

LineLengthFixer

Array items, method parameters, method call arguments, new arguments should be on same/standalone line to fit line length.

:wrench: configure it!

  • class: Symplify\CodingStandard\Fixer\LineLength\LineLengthFixer
diff
-function some($veryLong, $superLong, $oneMoreTime)
-{
+function some(
+    $veryLong,
+    $superLong,
+    $oneMoreTime
+) {
 }

-function another(
-    $short,
-    $now
-) {
+function another($short, $now) {
 }

MethodChainingNewlineFixer

Each chain method call must be on own line

  • class: Symplify\CodingStandard\Fixer\Spacing\MethodChainingNewlineFixer
diff
-$someClass->firstCall()->secondCall();
+$someClass->firstCall()
+->secondCall();

Doc block malform rules

Single-task rules that each fix one kind of @param/@return/@var malform. They are registered together in the docblock set and all handle the @phpstan- and @psalm- prefixed variants of these tags.

AddMissingParamNameFixer

Add a missing variable name to a @param annotation

  • class: Symplify\CodingStandard\Fixer\Commenting\AddMissingParamNameFixer
diff
 /**
- * @param string
+ * @param string $name
  */
 function getPerson($name)
 {
 }

AddMissingVarNameFixer

Add a missing variable name to an inline @var annotation

  • class: Symplify\CodingStandard\Fixer\Commenting\AddMissingVarNameFixer
diff
-/** @var int */
+/** @var int $value */
 $value = 1000;

DoubleAsteriskInlineVarFixer

Use a double asterisk /** doc block for an inline @var comment

  • class: Symplify\CodingStandard\Fixer\Commenting\DoubleAsteriskInlineVarFixer
diff
-/* @var int $variable */
+/** @var int $variable */
 $variable = 5;

FixParamNameTypoFixer

Fix a typo in the @param variable name to match the real argument

  • class: Symplify\CodingStandard\Fixer\Commenting\FixParamNameTypoFixer
diff
 /**
  * @param string $one
- * @param string $twoTypo
+ * @param string $two
  */
 function anotherFunction(string $one, string $two)
 {
 }

RemoveDeadParamFixer

Remove a dead @param line that has only a name and no type

  • class: Symplify\CodingStandard\Fixer\Commenting\RemoveDeadParamFixer
diff
 /**
  * @param string $name
- * @param $age
  */
 function withDeadParam(string $name, $age)
 {
 }

RemoveParamNameReferenceFixer

Remove the reference & from a @param variable name

  • class: Symplify\CodingStandard\Fixer\Commenting\RemoveParamNameReferenceFixer
diff
 /**
- * @param string &$name
+ * @param string $name
  */
 function paramReference($name)
 {
 }

RemoveSuperfluousReturnNameFixer

Remove a superfluous variable name from a @return annotation

  • class: Symplify\CodingStandard\Fixer\Commenting\RemoveSuperfluousReturnNameFixer
diff
 /**
- * @return int $value
+ * @return int
  */
 function function1(): int
 {
 }

RemoveSuperfluousVarNameFixer

Remove a superfluous variable name from a property @var annotation

  • class: Symplify\CodingStandard\Fixer\Commenting\RemoveSuperfluousVarNameFixer
diff
 /**
- * @var string $property
+ * @var string
  */
 private $property;

SingleLineInlineVarDocBlockFixer

Collapse a multi-line inline @var doc block into a single line

  • class: Symplify\CodingStandard\Fixer\Commenting\SingleLineInlineVarDocBlockFixer
diff
-/**
- * @var int $value
- */
+/** @var int $value */
 $value = 1000;

SwitchedTypeAndNameFixer

Reorder switched type and variable name in @param/@var annotation

  • class: Symplify\CodingStandard\Fixer\Commenting\SwitchedTypeAndNameFixer
diff
 /**
- * @param $a string
- * @param $b string|null
+ * @param string $a
+ * @param string|null $b
  */
 function test($a, string $b = null): string
 {
 }

RemovePropertyVariableNameDescriptionFixer

Remove docblock descriptions which duplicate their property name

  • class: Symplify\CodingStandard\Fixer\Annotation\RemovePropertyVariableNameDescriptionFixer
diff
 /**
- * @var string $name
+ * @var string
  */
 private $name;

RemoveMethodNameDuplicateDescriptionFixer

Remove docblock descriptions which duplicate their method name

  • class: Symplify\CodingStandard\Fixer\Annotation\RemoveMethodNameDuplicateDescriptionFixer
diff
 /**
- * Get name
  *
  * @return string
  */
 function getName()
 {
 }

RemovePHPStormAnnotationFixer

Remove "Created by PhpStorm" annotations

  • class: Symplify\CodingStandard\Fixer\Annotation\RemovePHPStormAnnotationFixer
diff
-/**
- * Created by PhpStorm.
- * User: ...
- * Date: 17/10/17
- * Time: 8:50 AM
- */
 class SomeClass
 {
 }

RemoveUselessDefaultCommentFixer

Remove useless PHPStorm-generated @todo comments, redundant "Class XY" or "gets service" comments etc.

  • class: Symplify\CodingStandard\Fixer\Commenting\RemoveUselessDefaultCommentFixer
diff
-/**
- * class SomeClass
- */
 class SomeClass
 {
-    /**
-     * SomeClass Constructor.
-     */
     public function __construct()
     {
-        // TODO: Change the autogenerated stub
-        // TODO: Implement whatever() method.
     }
 }

It also removes "Class representing XY" comments:

diff
-/**
- * Class representing TeamPlayer
- */
 class TeamPlayer
 {
 }

Comments that only repeat the class name are removed:

diff
-/**
- * TeamPlayer
- */
 class TeamPlayer
 {
 }

As well as the default doc block generated by the Doctrine ORM:

diff
-/**
- * This class was generated by the Doctrine ORM. Add your own custom
- * repository methods below.
- */
 class SomeRepository
 {
 }

SpaceAfterCommaHereNowDocFixer

Add space after nowdoc and heredoc keyword, to prevent bugs on PHP 7.2 and lower, see https://laravel-news.com/flexible-heredoc-and-nowdoc-coming-to-php-7-3

  • class: Symplify\CodingStandard\Fixer\Spacing\SpaceAfterCommaHereNowDocFixer
diff
 $values = [
      'Peter', 2 => 'Paul'];
+$friends = [
+    1 => 'Peter',
+    2 => 'Paul'
+];

StandaloneLinePromotedPropertyFixer

Promoted property should be on standalone line

  • class: Symplify\CodingStandard\Fixer\Spacing\StandaloneLinePromotedPropertyFixer
diff
 final class PromotedProperties
 {
-    public function __construct(public int $age, private string $name)
-    {
+    public function __construct(
+        public int $age,
+        private string $name
+    ) {
     }
 }

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

PHPcoding-standardcoding-styleecsphp

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言