PHP-CS-Fixer for Laravel 5.5+

GitHub license Maintenance GitHub release (latest by date) GitHub stars Packagist

This package allows to use PHP-CS-Fixer right into Laravel 5.5+ applications to format PHP code.


This package is an adapted copy of https://github.com/JackieDo/Artisan-PHP-CS-Fixer, credits and many thanks to JackieDo :-)

Any contribution or feedback is highly welcomed, please feel free to create a pull request or submit a new issue.

Quick start

Provided features

  • A PHP-CS-Fixer installation right into Laravel 5.5+ projects.
  • Commands to execute PHP-CS-Fixer via Laravel Artisan CLI :
    • php-cs-fixer:fix fixes php code for directories or files.
    • php-cs-fixer:describe describes fixer rule or ruleset.
    • php-cs-fixer:version display PHP-CS-Fixer version.
  • The php_cs_fixer helper to fix files from the code.

Installation

Install this package using Composer.

composer require bgaze/laravel-php-cs-fixer

To customize the configuration, publish it :

php artisan vendor:publish --tag=bgaze-php-cs-fixer-config

Configuration

Configuration isn't a standard Laravel config files as it returns an instance of \PhpCsFixer\Config.
It will be published into a .php_cs.dist file at the Laravel installation root.

For local development, you can also create a .php_cs file that should be ignored by your VCS.

To maintain compatibility with v1 of this package, config file will be resolved in this order:
.php_cs > .php_cs.dist > .php-cs > package default file

Usage

Please see PHP-CS-Fixer documentation for more details.

Fix using Artisan CLI

Fix your code with PHP Coding Standards.

Usage:

php artisan php-cs-fixer:fix [options] path1 [path2 path3 ...]

Argument & options:

path                             Path to directory or file (multiple values allowed).
--allow-risky                    Allow risky fixers.
--dry-run                        Only shows which files would have been modified, leaving your files unchanged.
--stop-on-violation              Stop execution on first violation.
--diff                           Also produce diff for each file.
--using-cache                    Enable cache usage.
--path-mode[=PATH-MODE]          Specify path mode (override|intersection). [default: "override"]
--config[=CONFIG]                The path to a config file.
--rules[=RULES]                  The rules to apply for fixer (comma separated).
--cache-file[=CACHE-FILE]        The path to the cache file.
--format[=FORMAT]                To output results in other formats.
--show-progress[=SHOW-PROGRESS]  Type of progress indicator (none|run-in|estimating). [default: "none"]
-h, --help                       Display this help message
-q, --quiet                      Do not output any message
-V, --version                    Display this application version
--ansi                           Force ANSI output
--no-ansi                        Disable ANSI output
-n, --no-interaction             Do not ask any interactive question
    --env[=ENV]                  The environment the command should run under
-v|vv|vvv, --verbose             Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Examples:

// Show which files in your project would have been modified, leaving them unchanged.
$ php artisan php-cs-fixer:fix --dry-run

// Fix all files in your project.
$ php artisan php-cs-fixer:fix

// Fix all files in the `app` directory.
$ php artisan php-cs-fixer:fix app

// Fix all files in the `app` directory with specific configuration file.
$ php artisan php-cs-fixer:fix --config="path/to/config/file" app

Fix from PHP code

The php_cs_fixer helper function wraps php-cs-fixer:fix command and allows to fix files right from the code.
It accept as arguments a path, or an array of paths, and an optional array of options, and returns the exit code of the command.

Examples :

// Quick.
php_cs_fixer('path/to/a/file/or/dir');

// Advanced.
php_cs_fixer(['path/to/file/or/dir/1', 'path/to/file/or/dir/2'], [
    '--allow-risky' => true,
    '--dry-run' => true,
    '--config' => 'path/to/a/config/file'
]);

Describe rule or set

Usage:

php-cs-fixer:describe [options] name

Argument & options:

name                  Name of rule / set.
-h, --help            Display this help message
-q, --quiet           Do not output any message
-V, --version         Display this application version
--ansi                Force ANSI output
--no-ansi             Disable ANSI output
-n, --no-interaction  Do not ask any interactive question
--env[=ENV]           The environment the command should run under
-v|vv|vvv, --verbose  Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Version

Displays PHP-CS-Fixer version installed.

Usage:

php artisan php-cs-fixer:version

Packages

Feel free to visit my other packages:

Bootstrap 4 forms builder for Laravel 5.8+

This package uses in background Laravel Collective HTML to simplify Bootstrap 4 forms creation into Laravel applications.
Model form binding and automatic error display are supported, as well as most of Bootstrap forms features : form layouts, custom fields, input groups, ...

Github Documentation

Bootstrap 4 dialogs

BSD is a tiny and flexible collection of dialog popups based on Bootstrap 4 modals.
Custom dialogs can be easily defined, in addition to built-in ones (alert, confirm and prompt).

Github Documentation

Bootstrap Color Palette

BCP is a simple color palette for Bootstrap 4, like in Google doc, built on the top of Bootstrap 4 Popover plugin.

Github Documentation

Laravel Kvstore

A simple and easy to use key-value database store for Laravel 5.5+
All values are stored into database and managed using cache to avoid unecessary queries.
Casting is supported to manage values type.

Github Documentation

Php DotEnv

A simple and standalone DotEnv parser for PHP 5.6+

Github Documentation

Blade Indenter

A very simple formatter for Laravel 5.8+ Blade templates

Github Documentation