PHPackages                             algoritma/php-coding-standards - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [PSR &amp; Standards](/categories/psr-standards)
4. /
5. algoritma/php-coding-standards

ActiveComposer-plugin[PSR &amp; Standards](/categories/psr-standards)

algoritma/php-coding-standards
==============================

A usefull PHP Coding Standard for your projects, based on PHPStan, PHP CS Fixer and Rector.

3.0.39(4mo ago)6667↓33.3%2GPL-3.0-or-laterPHPPHP &gt;=8.1CI passing

Since Nov 16Pushed 2mo agoCompare

[ Source](https://github.com/algoritma-dev/php-coding-standards)[ Packagist](https://packagist.org/packages/algoritma/php-coding-standards)[ RSS](/packages/algoritma-php-coding-standards/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (19)Versions (50)Used By (2)

Algoritma PHP Coding Standard
=============================

[](#algoritma-php-coding-standard)

VersionPHP version supported3.0&gt;= 8.1Installation
------------

[](#installation)

To install the coding standard, run the following command:

```
$ composer require --dev algoritma/php-coding-standards

```

When you install it, a plugin will ask you some questions to setup your project automatically.

The installer will add the `.php-cs-fixer.dist.php`, `rector.php`, and `phpstan.neon` files in your project root directory. You can then edit them manually if you need to make any changes.

The CS config will be configured to find your project files using composer autoload sources. Only `psr-0`, `psr-4` and `classmap` autoloads are supported.

The installer will also add five scripts in your `composer.json`;

```
"scripts": {
    "cs-check": "php-cs-fixer fix --dry-run --diff --allow-risky yes",
    "cs-fix": "php-cs-fixer fix --diff --allow-risky yes",
    "rector-check": "rector process --dry-run",
    "rector-fix": "rector process",
    "phpstan": "phpstan analyze"
}
```

Usage
-----

[](#usage)

To start code style check:

```
$ composer cs-check

```

To automatically fix code style:

```
$ composer cs-fix

```

To automatically check for refactor:

```
$ composer rector-check

```

To automatically refactor fix:

```
$ composer rector-fix

```

To run static analisys check:

```
$ composer phpstan

```

Configuration Generation
------------------------

[](#configuration-generation)

If you need to regenerate the default configuration files, use the following commands:

To regenerate the default `.php-cs-fixer.dist.php` configuration:

```
$ composer algoritma-cs-create-config

```

```
$ composer algoritma-cs-create-config --help

Usage:
  algoritma-cs-create-config [options]

Options:
      --no-dev                   Do not include autoload-dev directories
      --no-risky                 Do not include risky rules

```

To regenerate the default `rector.php` configuration:

```
$ composer algoritma-rector-create-config

```

```
$ composer algoritma-rector-create-config --help

Usage:
  algoritma-rector-create-config [options]

Options:
      --no-dev                   Do not include autoload-dev directories

```

To regenerate the default `phpstan.neon` configuration:

```
$ composer algoritma-phpstan-create-config

```

```
$ composer algoritma-phpstan-create-config --help

Usage:
  algoritma-phpstan-create-config [options]

Options:
      --no-dev                   Do not include autoload-dev directories

```

Main Dependencies
-----------------

[](#main-dependencies)

This project relies on the following tools to enforce coding standards:

- [PHP-CS-Fixer](https://github.com/FriendsOfPHP/PHP-CS-Fixer)
- [Rector](https://github.com/rectorphp/rector)
- [PHPStan](https://github.com/phpstan/phpstan)

Configuration
-------------

[](#configuration)

For more information on how to configure the tools, please refer to their official documentation.

Risky rules (PHP-CS-Fixer)
--------------------------

[](#risky-rules-php-cs-fixer)

Risky rules may be unstable, and cause unintended behavioral changes to your code. If you want to add these rules, you can create your own `.php-cs-fixer.php`configuration:

```
