Skip to content
On this page

PHP CS Fixer

A tool to automatically fix PHP Coding Standards issues

Installatie

PHP Stan installeren in je project kan via Composer:

bash
composer require --dev friendsofphp/php-cs-fixer

Configuratie

.php-cs

php
<?php

$finder = PhpCsFixer\Finder::create()
    ->in(__DIR__)
    ->exclude(['bootstrap', 'storage', 'vendor'])
    ->name('*.php')
    ->name('_ide_helper')
    ->notName('*.blade.php')
    ->ignoreDotFiles(true)
    ->ignoreVCS(true);

$config = new PhpCsFixer\Config();
return $config->setRules([
        '@Symfony' => true,
        '@PSR1' => true,
        '@PSR2' => true,
        '@PSR12' => true,
        'no_useless_else' => true,
        'yoda_style' => false,
        'modernize_types_casting' => true,
    ])
    ->setFinder($finder);

package.json

json
"lint-staged": {
  "*.php": "php vendor/bin/php-cs-fixer fix --config .php-cs --allow-risky=yes"
}

Gebruik

Manueel:

bash
vendor/bin/php-cs-fixer fix src

PHPStorm

How to configure PHPStorm to use PHP-CS-Fixer