# 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. [![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