Greynoise Design - Laravel 5 Standard
Version 1.0.2, (*1)
Requirements
PHP_CodeSniffer 3. (3.1.1 or greater)., (*2)
Global install (Recommended)
Globally install PHP_CodeSniffer with one of the various methods. (Skip this step if you already have it installed.), (*3)
Once complete you should be able to execute phpcs -i on the command line., (*4)
You should see something like:-, (*5)
The installed coding standards are MySource, PEAR, PSR1, PSR2, Squiz and Zend., (*6)
(Recommended) use composer..., (*7)
composer global require greynoise-design/laravel-coding-standard, (*8)
or clone this repository..., (*9)
git clone -b master --depth 1 https://github.com/greynoise-design/laravel-coding-standard.git., (*10)
or download., (*11)
Take note of the paths where they were installed., (*12)
(Recommended) Create a symbolic link to the 'laravel-coding-standard/GreynoiseLaravel' directory in 'php_codesniffer/src/Standards/' eg., (*13)
ln -s ~/Documents/Projects/laravel-coding-standard/GreynoiseLaravel ~/.composer/vendor/squizlabs/php_codesniffer/src/Standards/GreynoiseLaravel, (*14)
or copy the GreynoiseLaravel directory to php_codesniffer/src/Standards/, (*15)
Executing phpcs -i should now show GreynoiseLaravel installed eg., (*16)
The installed coding standards are GreynoiseLaravel, MySource, PEAR, PSR1, PSR2, Squiz and Zend., (*17)
You should now be able to set 'GreynoiseLaravel' as the phpcs standard in the plugin/editor/IDE of your choice., (*18)
Composer install for a single project
cd /Path/To/MyProject, (*19)
composer require greynoise-design/laravel-coding-standard, (*20)
Set the 'phpcs standard path' and 'phpcbf standard path' in your editor/plugin config to:, (*21)
'/Path/To/MyProject/vendor/laravel-coding-standard/GreynoiseLaravel/ruleset.xml', (*22)
Command line use
Sniffing errors & warnings (reporting).
Single file..., (*23)
phpcs /Path/To/MyFile.php --standard='/Path/To/laravel-coding-standard/GreynoiseLaravel/ruleset.xml', (*24)
or if globally installed., (*25)
phpcs /Path/To/MyFile.php --standard=GreynoiseLaravel, (*26)
Directory (recursive)., (*27)
phpcs /Path/To/MyProject --standard='/Path/To/laravel-coding-standard/GreynoiseLaravel/ruleset.xml', (*28)
or if globally installed., (*29)
phpcs /Path/To/MyProject --standard=GreynoiseLaravel, (*30)
Fixing fixable errors.
Single file., (*31)
phpcbf /Path/To/MyFile.php --standard='/Path/To/laravel-coding-standard/GreynoiseLaravel/ruleset.xml', (*32)
or if globally installed., (*33)
phpcbf /Path/To/MyFile.php --standard=GreynoiseLaravel, (*34)
Directory (recursive)., (*35)
phpcbf /Path/To/MyProject --standard='/Path/To/laravel-coding-standard/GreynoiseLaravel/ruleset.xml', (*36)
or if globally installed., (*37)
phpcbf /Path/To/MyProject --standard=GreynoiseLaravel, (*38)
Example editor configs
SublimeText project config
Project > Edit Project, (*39)
Set it to your preference., (*40)
{
"SublimeLinter":
{
"linters":
{
"phpcs":
{
"@disable": false,
"cmd": "/Path/To/php_codesniffer/bin/phpcs",
// Or if installed globally. "cmd": "phpcs",
"standard": "/Path/To/laravel-coding-standard/GreynoiseLaravel/ruleset.xml",
// Exclude folders and files in the linting environment.
// (Matches exclude-patterns in ruleser.xml).
"excludes":
[
"*/config/*",
"*/cache/*",
"*/database/*",
"*/docs/*",
"*/migrations/*",
"*/public/index.php",
"*/vendor/*",
"*/storage/*",
"*/*.blade.php",
"*/*.css",
"*/*.js",
"*/*.xml",
"*/autoload.php",
"*/Middleware/*",
"*/Console/Kernel.php",
"*/Exceptions/Handler.php",
"*/Http/Kernel.php",
"*/Providers/*"
],
}
}
},
"folders":
[
{
"path": "/Path/To/MyProject"
}
],
"settings":
{
"phpcs":
{
"extensions_to_execute":
[
"php"
],
"phpcs_executable_path": "/Path/To/php_codesniffer/bin/phpcs",
// Or if installed globally. "phpcbf_executable_path": "phpcs",
"phpcs_additional_args":
{
"--standard": "/Path/To/laravel-coding-standard/GreynoiseLaravel/ruleset.xml",
// Optional don't show warnings
// "-n": ""
},
"phpcbf_executable_path": "/Path/To/php_codesniffer/bin/phpcbf",
// Or if installed globally. "phpcbf_executable_path": "phpcbf",
"phpcbf_additional_args":
{
"--standard": "/Path/To/laravel-coding-standard/GreynoiseLaravel/ruleset.xml",
// Optional don't fix warnings (if they're fixable)
// "-n": ""
},
// Execute the sniffer on file save. (Using contextual menu instead)
"phpcs_execute_on_save": false,
// Show the error list after save. (Using sublime linter instead)
"phpcs_show_errors_on_save": false,
// Show the errors in the quick panel so you can then goto line. (Gets annoying)
"phpcs_show_quick_panel": false,
// Turn the debug output on/off.
"show_debug": false
}
}
}