# Ely.by PHP-CS-Fixer rules Set of PHP-CS-Fixer rules used in development of Ely.by PHP projects. It's suited for PHP 7.4 and above. You can use it as a ready-made set of rules or [just some of them](#using-our-fixers). [![Latest Version on Packagist][ico-version]][link-packagist] [![Total Downloads][ico-downloads]][link-downloads] [![Software License][ico-license]](LICENSE.md) [![Build Status][ico-build-status]][link-build-status] ## Installation First of all install Ely.by PHP-CS-Fixer rules via composer with [PHP-CS-Fixer](https://github.com/FriendsOfPHP/PHP-CS-Fixer): ```sh composer require --dev friendsofphp/php-cs-fixer ely/php-code-style ``` Then create a file `.php-cs-fixer.php` with the following contents: ```php in(__DIR__); return \Ely\CS\Config::create() ->setFinder($finder); ``` And that's it. You can now find code style violations with following command: ```sh vendor/bin/php-cs-fixer --diff --dry-run -v fix ``` And then completely fix them all with: ```sh vendor/bin/php-cs-fixer fix ``` ### Configuration You can pass a custom set of rules to the `\Ely\CS\Config::create()` call. For example, it can be used to validate a project with PHP 7.4 compatibility: ```php [ 'elements' => ['arrays', 'arguments'], ], ])->setFinder($finder); ``` ## Code style Our code style is based primarily on [PSR-2](https://www.php-fig.org/psr/psr-2/), while borrowing some ideas from [PSR-12](https://github.com/php-fig/fig-standards/blob/92b198bb/proposed/extended-coding-style-guide.md) with some changes. ### Example This example encompasses some of the rules below as a quick overview: ```php b) { $result = bar(); } else { $result = BazClass::bar($this->field1, $this->field2); } return $result; } public function setToNull(): self { $this->field1 = null; return $this; } } ``` **Key differences:** * Opening braces for classes MUST be **on the same line**. * Opening braces for methods MUST be **on the next line**. **Additional rules:** * There MUST be one empty line before `return` statement, except when there is only one statement before it. ```php registerCustomFixers(new \Ely\CS\Fixers()); ``` And then you'll be able to use our custom rules. ### `Ely/align_multiline_parameters` Forces aligned or not aligned multiline function parameters: ```diff --- Original +++ New @@ @@ function foo( string $string, - int $index = 0, - $arg = 'no type', + int $index = 0, + $arg = 'no type', ): void {} ``` **Configuration:** * `variables` - when set to `true`, forces variables alignment. On `false` forces strictly no alignment. You can set it to `null` to disable touching of variables. **Default**: `true`. * `defaults` - when set to `true`, forces defaults alignment. On `false` forces strictly no alignment. You can set it to `null` to disable touching of defaults. **Default**: `false`. ### `Ely/blank_line_around_class_body` Ensure that a class body contains one blank line after its definition and before its end: ```diff --- Original +++ New @@ @@ foo(); return 'okay'; } ``` ### `Ely/line_break_after_statements` Ensures that there is one blank line above the next statements: `if`, `switch`, `for`, `foreach`, `while` and `do-while`. ```diff --- Original +++ New @@ @@