PHPackages                             jubeki/laravel-code-style - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. jubeki/laravel-code-style

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

jubeki/laravel-code-style
=========================

Combine Custom Fixers with the ruleset of Laravel Pint to fix your code style in Laravel Applications/Packages.

2.20.0(2mo ago)56521.7k↑26.3%78MITPHPPHP ^8.0CI passing

Since Apr 23Pushed 2mo ago2 watchersCompare

[ Source](https://github.com/Jubeki/laravel-code-style)[ Packagist](https://packagist.org/packages/jubeki/laravel-code-style)[ Docs](https://github.com/Jubeki/laravel-code-style)[ RSS](/packages/jubeki-laravel-code-style/feed)WikiDiscussions 2.x Synced 1mo ago

READMEChangelog (10)Dependencies (8)Versions (46)Used By (8)

 Laravel Code Style
====================

[](#----laravel-code-style)

 Combine Custom Fixers with the ruleset of Laravel Pint

 [![GitHub Workflow Status](https://camo.githubusercontent.com/0677cd570d1bc105ac10433dd973f6b9e75f9e84dd933106fb7482506072edf6/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f4a7562656b692f6c61726176656c2d636f64652d7374796c652f74657374732e796d6c3f6272616e63683d322e78266c6162656c3d5465737473266c6f676f3d676974687562267374796c653d666f722d7468652d6261646765)](https://github.com/Jubeki/laravel-code-style/actions) [![Downloads Total](https://camo.githubusercontent.com/ce64da8512ad7d87d30cff27b3f65fd8762a8740d88dc4d10d1eff336129a56c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f4a7562656b692f6c61726176656c2d636f64652d7374796c653f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/jubeki/laravel-code-style/stats) [![License Type](https://camo.githubusercontent.com/d0a947b5ecd4a410cb58dc91421897f5b276144ee97c897a8a3df61be2280a89/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f4a7562656b692f6c61726176656c2d636f64652d7374796c653f7374796c653d666f722d7468652d6261646765)](LICENSE.md) [![Latest released version](https://camo.githubusercontent.com/7226e69092aa0bd21db880d3e8268b1fe17d1e8723edd665a22ad5efa114a292/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f4a7562656b692f6c61726176656c2d636f64652d7374796c653f736f72743d73656d766572267374796c653d666f722d7468652d6261646765)](https://github.com/Jubeki/laravel-code-style/releases/latest)

 [![Supports Laravel 9.x - 13.x](https://camo.githubusercontent.com/bc420aea1a06a8111f1c368581d2acdd12f8300b376dcb67b6132aba90b8aff9/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d392e78253230746f25323031332e782d4646324432303f7374796c653d666f722d7468652d6261646765266c6f676f3d6c61726176656c)](https://laravel.com) [![Supports PHP 8.0 - 8.5](https://camo.githubusercontent.com/340e6d62cdb08f8bd290008cf5993c1e19d27483815b67d13307db615aa917d7/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e30253230746f253230382e352d3737374242343f7374796c653d666f722d7468652d6261646765266c6f676f3d706870)](https://php.net)

Introduction
------------

[](#introduction)

This package provides automatic code style checking and formatting for Laravel applications and packages using the same ruleset as [Laravel Pint](https://github.com/laravel/pint). This package is built on top of [PHP-CS-Fixer](https://github.com/PHP-CS-Fixer/PHP-CS-Fixer) and therefor gives you the ability to add custom fixers. (which is one of the shortcomings of Laravel Pint)

Installation
------------

[](#installation)

```
composer require jubeki/laravel-code-style --dev
```

Once the package is installed you should publish the configuration.

```
php artisan vendor:publish --provider="Jubeki\LaravelCodeStyle\ServiceProvider"
```

Publishing the config will add a `.php-cs-fixer.dist.php` configuration file to the root of your project. You may customize this file as needed and then commit it to your version control system.

A cache file will be written to `.php-cs-fixer.cache` in the project root the first time you run the fixer. You should ignore this file so it is not added to your version control system.

```
echo '.php-cs-fixer.cache' >> .gitignore
```

Usage
-----

[](#usage)

Once the package is installed you can check and fix your code formatting with the on subcommand of `vendor/bin/php-cs-fixer`.

### Automatically fix the code style

[](#automatically-fix-the-code-style)

To automatically fix the code style of your project you may use the following command:

```
vendor/bin/php-cs-fixer fix
```

By default only the file names of every file fixed will be shown. To see a full diff of every change append the `--diff` flag.

### Checking for code style violations

[](#checking-for-code-style-violations)

If you would like to check the formatting without actually altering any files you should use the `fix` command with the `--dry-run` flag.

```
vendor/bin/php-cs-fixer fix --dry-run --diff
```

In dry-run mode any violations will [cause the command to return a non-zero exit code](https://github.com/FriendsOfPhp/PHP-CS-Fixer#exit-code). You can use this command to fail a CI build or git commit hook.

### Composer script

[](#composer-script)

To make checking and fixing code style easier for contributors to your project it's recommended to add the commands as a [composer script](https://getcomposer.org/doc/articles/scripts.md):

```
{
    "scripts": {
        "check-style": "php-cs-fixer fix --dry-run --diff",
        "fix-style": "php-cs-fixer fix"
    }
}
```

### More Options

[](#more-options)

For a complete list of options please consult the [PHP-CS-Fixer documentation](https://github.com/FriendsOfPhp/PHP-CS-Fixer#usage).

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

[](#configuration)

The default configuration is published as `.php-cs-fixer.dist.php` in the project root. You can customize this file to change options such as the paths searched or the fixes applied.

### Paths

[](#paths)

You can change the paths searched for PHP files by chaining method calls onto the `PhpCsFixer\Finder` instance being passed to the `Jubeki\LaravelCodeStyle\Config::setFinder` method.

For example, to search the `examples` directory you would append `->in('examples')`:

```
