wayofdev/cs-fixer-config

Package adds custom rule-sets to php-cs-fixer

Fund package maintenance!
wayofdev

v1.2.60 2023-09-13 10:11 UTC

README


logo.gh-light-mode-only.png#gh-light-mode-only logo.gh-dark-mode-only.png#gh-dark-mode-only

Build Status Total Downloads Latest Stable Version Software License Commits since latest release

PHP CS Fixer Config

Wrapper with pre-defined rules around the PHP-CS-Fixer package — A tool to automatically fix PHP Coding Standards issues.

If you like/use this package, please consider starring it. Thanks!


💿 Installation

→ Using composer

Require as dependency:

$ composer req wayofdev/cs-fixer-config

🛠 Configuration

  1. Create PHP file and name it .php-cs-fixer.dist.php and place it inside root directory of project. It will be recognized by PHP CS Fixer automatically.

  2. Example contents of .php-cs-fixer.dist.php file:

    <?php
    
    declare(strict_types=1);
    
    use WayOfDev\PhpCsFixer\Config\ConfigBuilder;
    use WayOfDev\PhpCsFixer\Config\RuleSets\DefaultSet;
    
    require_once 'vendor/autoload.php';
    
    return ConfigBuilder::createFromRuleSet(new DefaultSet())
        ->inDir(__DIR__ . '/src')
        ->inDir(__DIR__ . '/tests')
        ->addFiles([__FILE__])
        ->getConfig();
  3. Place .php-cs-fixer.cache file into .gitignore


💻 Usage

→ Running

Fix coding standards by simply running console command:

$ php vendor/bin/php-cs-fixer fix -v

→ Using Makefile

To use with our Makefile:

  1. Add scripts section to composer.json:

    {
        "scripts": {
            "cs-fix": "php vendor/bin/php-cs-fixer fix -v",
            "cs-diff": "php vendor/bin/php-cs-fixer fix --dry-run -v --diff"
        }
    }
  2. Use Makefile code to run PHP-CS-Fixer tests:

    # Run inspections and fix code
    $ make cs-fix
    
    # Check coding standards without applying the fix
    $ make cs-diff

🧪 Running Tests

→ PHPUnit tests

To run tests, run the following command:

$ make test

→ Static Analysis

Code quality using PHPStan:

$ make stan

→ Coding Standards Fixing

Fix code using The PHP Coding Standards Fixer (PHP CS Fixer) to follow our standards:

$ make cs-fix

🤝 License

Licence


🙆🏼‍♂️ Author Information

Created in 2022 by lotyp / wayofdev


🧱 Resources