Giter Club home page Giter Club logo

coding-standard's Introduction

Coding Standard

Downloads

Set of rules for PHP_CodeSniffer and PHP-CS-Fixer used by Symplify projects.

They run best with EasyCodingStandard.


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]);

12 Rules Overview

ArrayListItemNewlineFixer

Indexed PHP array item has to have one line per item

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

ArrayOpenerAndCloserNewlineFixer

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

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

BlankLineAfterStrictTypesFixer

Strict type declaration has to be followed by empty line

 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.

๐Ÿ”ง configure it!

-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

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

ParamReturnAndVarTagMalformsFixer

Fixes @param, @return, @var and inline @var annotations broken formats

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

RemovePHPStormAnnotationFixer

Remove "Created by PhpStorm" annotations

-/**
- * 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 SomeClass
- */
 class SomeClass
 {
-    /**
-     * SomeClass Constructor.
-     */
     public function __construct()
     {
-        // TODO: Change the autogenerated stub
-        // TODO: Implement whatever() method.
     }
 }

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

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

StandaloneLineConstructorParamFixer

Constructor param should be on a standalone line to ease git diffs on new dependency

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

StandaloneLineInMultilineArrayFixer

Indexed arrays must have 1 item per line

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

StandaloneLinePromotedPropertyFixer

Promoted property should be on standalone line

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.