PHPackages                             matt-allan/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. matt-allan/laravel-code-style

Abandoned → [jubeki/laravel-code-style](/?search=jubeki%2Flaravel-code-style)ArchivedLibrary[Utility &amp; Helpers](/categories/utility)

matt-allan/laravel-code-style
=============================

Code formatting for Laravel projects

0.7.1(4y ago)395754.0k↓10.6%318MITPHPPHP &gt;=7.4

Since Apr 23Pushed 4y ago10 watchersCompare

[ Source](https://github.com/matt-allan/laravel-code-style)[ Packagist](https://packagist.org/packages/matt-allan/laravel-code-style)[ Docs](https://github.com/matt-allan/laravel-code-style)[ RSS](/packages/matt-allan-laravel-code-style/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (7)Versions (13)Used By (8)

Laravel Code Style
------------------

[](#laravel-code-style)

[![Packagist License](https://camo.githubusercontent.com/e3ac4ddfcac570896801f55cd9606a5519ff6b8e4c7959fed2f5f4da619e93a4/68747470733a2f2f706f7365722e707567782e6f72672f6d6174742d616c6c616e2f6c61726176656c2d636f64652d7374796c652f6c6963656e73652e706e67)](http://choosealicense.com/licenses/mit/)[![Latest Stable Version](https://camo.githubusercontent.com/f8a7bf82b4947398d6f711db42bf0144b0010719ea410d9641cc3df1dedbe4b8/68747470733a2f2f706f7365722e707567782e6f72672f6d6174742d616c6c616e2f6c61726176656c2d636f64652d7374796c652f76657273696f6e2e706e67)](https://packagist.org/packages/matt-allan/laravel-code-style)[![Tests](https://github.com/matt-allan/laravel-code-style/workflows/Tests/badge.svg)](https://github.com/matt-allan/laravel-code-style/workflows/Tests/badge.svg)

> ⚠️ This package is no longer maintained. See [Jubeki/laravel-code-style](https://github.com/Jubeki/laravel-code-style) for a maintained fork.

This package provides automatic code style checking and formatting for Laravel applications and packages. Your code is formatted following Laravel's code style guide.

The package adds the [php-cs-fixer](https://github.com/FriendsOfPhp/PHP-CS-Fixer) tool and a community maintained ruleset to your application. The ruleset is a best effort attempt to match the code style the Laravel framework itself uses. Check out an [example](./examples/User.php) to see what the code style looks like.

You might want to use this package if you are writing a Laravel application, package or tutorial and you want to match the framework's code style.

If you are wondering why this package exists you can [read the announcement post](https://mattallan.me/posts/automate-code-formatting-for-laravel-projects/).

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

[](#installation)

> ⚠️ These docs are for the latest version. If you are using an older version you can find the docs for previous releases [here](#releases).

Require this package with composer. It is recommended to only require the package for development.

```
composer require matt-allan/laravel-code-style --dev
```

The service provider will be automatically registered using [package discovery](https://laravel.com/docs/5.8/packages#package-discovery).

If you don't use auto-discovery you should add the service provider to the providers array in `config/app.php`.

```
// existing providers...
MattAllan\LaravelCodeStyle\ServiceProvider::class,
```

Once the package is installed you should publish the configuration.

```
php artisan vendor:publish --provider="MattAllan\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. The `.php-cs-fixer.dist.php` file should be committed to version control.

A cache file will be written to `.php_cs.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.cache' >> .gitignore
```

Usage
-----

[](#usage)

Once the package is installed you can check and fix your code formatting with the `php-cs-fixer` command. The command will be available in Composer's `vendor/bin` directory.

### Fixing

[](#fixing)

To automatically fix the code style of your project you may use the `php-cs-fixer fix` command.

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

This will automatically fix the code style of every file in your project.

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.

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

### Checking

[](#checking)

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).

The following example allows anyone to check the code style by calling `composer check-style` and to fix the code style with `composer fix-style`.

```
{
    // ...
    "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 `MattAllan\LaravelCodeStyle\Config::setFinder` method.

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

```
