Owen Conti

Setting Up PHP CodeSniffer for a Laravel Application

Posted on under Laravel by Owen Conti.

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

First, install the dependency:

1composer require "squizlabs/php_codesniffer=*"

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

1<?xml version="1.0"?>
2<ruleset name="Standard">
3 <rule ref="PSR2">
4 <exclude name="PSR1.Methods.CamelCapsMethodName"/>
5 </rule>
6</ruleset>

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


Thanks for reading this article!

Hopefully you found this article useful! If you did, share it on Twitter!

Found an issue with the article? Submit your edits against the repository.