Setting up PHP CodeSniffer for a Laravel Application

Published under Laravel

Here's how you can quickly get started with linting your PHP code using the CodeSniffer library.

First, install the dependency:

composer require "squizlabs/php_codesniffer=*"

Then, create a file at the root of your repo: phpcs.xml

<?xml version="1.0"?>
<ruleset name="Standard">
    <rule ref="PSR2">
        <exclude name="PSR1.Methods.CamelCapsMethodName"/>

This file tells CodeSniffer which ruleset and rules you want to use. The above will use the PSR2 ruleset, while excluding the CamelCapsMethodName rule (I prefer the it_does_something method name formatting for tests).