PHPackages                             shawnveltman/phpcsfixer-helper - 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. shawnveltman/phpcsfixer-helper

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

shawnveltman/phpcsfixer-helper
==============================

Collection of my PHP CS Fixer rules to make it easy to share between projects

0674PHP

Since Jun 3Pushed 1y ago1 watchersCompare

[ Source](https://github.com/shawnveltman/phpcsfixer-helper)[ Packagist](https://packagist.org/packages/shawnveltman/phpcsfixer-helper)[ RSS](/packages/shawnveltman-phpcsfixer-helper/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependenciesVersions (1)Used By (0)

Very short description of the package
=====================================

[](#very-short-description-of-the-package)

[![Latest Version on Packagist](https://camo.githubusercontent.com/56e1451500bb8fa254f33b9211fd4e77bd090eb35993738e9dc6129fc6441c76/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f736861776e76656c746d616e2f706870637366697865722d68656c7065722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/shawnveltman/phpcsfixer-helper)[![Total Downloads](https://camo.githubusercontent.com/7047a5469d02557428af7a730097e71ef5e2b7e676dbc5c34a73f3a86c2e013a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f736861776e76656c746d616e2f706870637366697865722d68656c7065722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/shawnveltman/phpcsfixer-helper)[![GitHub Actions](https://github.com/shawnveltman/phpcsfixer-helper/actions/workflows/main.yml/badge.svg)](https://github.com/shawnveltman/phpcsfixer-helper/actions/workflows/main.yml/badge.svg)

This allows our team to share the same code styling, to reduce the amount of time we need to discuss those things, as well as sorting through changes between commits that are only formating related.

Prerequisites
-------------

[](#prerequisites)

If you don't already have PhpCsFixer and Husky installed, then copy &amp; paste below into terminal:

```
composer require friendsofphp/php-cs-fixer --dev
npm i -D husky lint-staged@^11.x.x
npm install --save-dev @shufo/prettier-plugin-blade prettier
npx husky init
```

Then, update the .husky/pre-commit file to only have this line:

```
npx lint-staged

```

Then, add this line to package.json (this assumes your Php CS Fixer file is called .php-cs-fixer.php, change as needed):

```
"lint-staged": {
    "*.php": "php ./vendor/bin/php-cs-fixer fix --config .php-cs-fixer.php",
    "*.blade.php": "node_modules/.bin/prettier --write resources/**/*.blade.php"
  },
```

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

[](#installation)

You can install the package via composer:

```
composer require shawnveltman/phpcsfixer-helper --dev
```

Once you've installed it, create a new file called .php-cs-fixer.php in your base directory.

Update .gitignore
-----------------

[](#update-gitignore)

Add .php-cs-fixer.cache to your .gitignore file!

Usage
-----

[](#usage)

After installing the package, navigate to your PHP CS Fixer file (ie .php-cs-fixer.php), and replace the existing $rules array with:

```
use Shawnveltman\PhpcsfixerHelper\PhpcsfixerHelper;

$helper = new PhpcsfixerHelper();
$rules = $helper->get_style_rules();
```

Fixer File
----------

[](#fixer-file)

If you don't have a fixer file, you can use the template below to your .php-cs-fixer.php file:

```
