2017 © Pedro Peláez
 

library coding-standard

Set of Symplify rules for PHP_CodeSniffer and PHP CS Fixer.

image

symplify/coding-standard

Set of Symplify rules for PHP_CodeSniffer and PHP CS Fixer.

  • PHP
  • 15 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 100 Versions
  • 39 % Grown

The README.md

Coding Standard

Downloads, (*1)

Set of rules for PHP_CodeSniffer and PHP-CS-Fixer used by Symplify projects., (*2)

They run best with EasyCodingStandard., (*3)


, (*4)

Install

composer require symplify/coding-standard --dev
composer require symplify/easy-coding-standard --dev
  1. Run with ECS:
# ecs.php
 use Symplify\EasyCodingStandard\Config\ECSConfig;
+use Symplify\EasyCodingStandard\ValueObject\Set\SetList;

 return static function (ECSConfig $ecsConfig): void {
+    $ecsConfig->sets([SetList::SYMPLIFY]);


, (*5)

12 Rules Overview

ArrayListItemNewlineFixer

Indexed PHP array item has to have one line per item, (*6)

-$value = ['simple' => 1, 'easy' => 2];
+$value = ['simple' => 1,
+'easy' => 2];


, (*7)

ArrayOpenerAndCloserNewlineFixer

Indexed PHP array opener [ and closer ] must be on own line, (*8)

-$items = [1 => 'Hey'];
+$items = [
+1 => 'Hey'
+];


, (*9)

BlankLineAfterStrictTypesFixer

Strict type declaration has to be followed by empty line, (*10)

 declare(strict_types=1);
+
 namespace App;


, (*11)

LineLengthFixer

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

:wrench: configure it!, (*13)

-function some($veryLong, $superLong, $oneMoreTime)
-{
+function some(
+    $veryLong,
+    $superLong,
+    $oneMoreTime
+) {
 }

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


, (*14)

MethodChainingNewlineFixer

Each chain method call must be on own line, (*15)

-$someClass->firstCall()->secondCall();
+$someClass->firstCall()
+->secondCall();


, (*16)

ParamReturnAndVarTagMalformsFixer

Fixes @param, @return, @var and inline @var annotations broken formats, (*17)

 /**
- * @param string
+ * @param string $name
  */
 function getPerson($name)
 {
 }


, (*18)

RemovePHPStormAnnotationFixer

Remove "Created by PhpStorm" annotations, (*19)

-/**
- * Created by PhpStorm.
- * User: ...
- * Date: 17/10/17
- * Time: 8:50 AM
- */
 class SomeClass
 {
 }


, (*20)

RemoveUselessDefaultCommentFixer

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

-/**
- * class SomeClass
- */
 class SomeClass
 {
-    /**
-     * SomeClass Constructor.
-     */
     public function __construct()
     {
-        // TODO: Change the autogenerated stub
-        // TODO: Implement whatever() method.
     }
 }


, (*22)

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, (*23)

 $values = [
     <<<RECTIFY
 Some content
-RECTIFY,
+RECTIFY
+,
     1000
 ];


, (*24)

StandaloneLineConstructorParamFixer

Constructor param should be on a standalone line to ease git diffs on new dependency, (*25)

 final class PromotedProperties
 {
-    public function __construct(int $age, string $name)
-    {
+    public function __construct(
+        int $age,
+        string $name
+    ) {
     }
 }


, (*26)

StandaloneLineInMultilineArrayFixer

Indexed arrays must have 1 item per line, (*27)

-$friends = [1 => 'Peter', 2 => 'Paul'];
+$friends = [
+    1 => 'Peter',
+    2 => 'Paul'
+];


, (*28)

StandaloneLinePromotedPropertyFixer

Promoted property should be on standalone line, (*29)

 final class PromotedProperties
 {
-    public function __construct(public int $age, private string $name)
-    {
+    public function __construct(
+        public int $age,
+        private string $name
+    ) {
     }
 }


, (*30)

The Versions