PHP-CS-Fixer for Laravel 5.5+

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

This package allows you to use PHP-CS-Fixer in 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 in 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 displays the 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 file 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 you to fix files right from the code.
It accepts 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 the installed PHP-CS-Fixer version.

Usage:

php artisan php-cs-fixer:version

Other packages

Feel free to visit my other packages:

bgaze/bootstrap-form

Bootstrap 4 & 5 forms builder for Laravel 12+

This package simplifies Bootstrap 4 & 5 forms creation in Laravel applications 12+
It renders Bootstrap 5 markup by default and fully supports Bootstrap 4 for backward compatibility.
Model form binding and automatic error display are supported, as well as most Bootstrap form features: form layouts, custom fields, input groups, and more.

Github Documentation

bgaze/laravel-kvstore

Key-value store for Laravel 12 & 13

A database-backed key-value store for Laravel 12 & 13, sized for settings: read on most requests, written rarely.
The whole store is cached as one single entry, so a cold read costs one query for every key at once.
Each entry carries its own cast, so a value always reads back as what it was written as.

Github Documentation

SnapStack

100% local browser captures for your AI assistant

SnapStack is a browser extension that captures any tab in one click and stacks it locally, so your AI assistant can read the screenshots on demand over MCP.
Nothing is ever uploaded: captures go only to a small server on your own machine. No account, no telemetry.
Works with any MCP-capable client (Claude Code and others), on Chrome, Edge and Firefox.

Github Documentation

@bgaze/color-palette

A grid colour picker in the spirit of Google Docs

Vanilla TypeScript, with a single runtime dependency for the positioning.
It works standalone, ships optional Bootstrap 4 and Bootstrap 5 themes, and is accessible on purpose.

Github Documentation