rroek / symfony3-custom-coding-standard
Customized CodeSniffer ruleset for the Symfony3 projects
Installs: 16
Dependents: 0
Suggesters: 0
Security: 0
Stars: 3
Watchers: 3
Forks: 0
Open Issues: 0
Type:coding-standard
Requires
This package is auto-updated.
Last update: 2025-03-06 20:46:39 UTC
README
This is a fork of https://github.com/djoos/Symfony2-coding-standard
These are the Symfony2 standards, but tweaked to meet some needs we have in our projects to my job.
For example to comply with PSR-12 for PHP 7
Installation
Composer
This standard can be installed with the Composer dependency manager.
- Add the repository to your composer.json:
composer require rroek/symfony3-custom-coding-standard
- Add the coding standard as a dependency of your project
"require-dev": { "RRoek/symfony3-custom-coding-standard": "^3.0" },
- Add the coding standard to the PHP_CodeSniffer install path
The path is relative to the php_codesniffer install path.
This is important to make it work both in your vagrant, windows, local machine and/or PHPStorm.
i.e. for your project with dependencies ruled by composer :
./vendor/bin/phpcs --config-set installed_paths ../../RRoek/symfony3-custom-coding-standard
-
Check the installed coding standards for "Symfony3RRoek"
bin/phpcs -i
-
Done!
bin/phpcs --standard=Symfony3RRoek /path/to/code (i.e. src)
-
(optional) Set up PHPStorm
- Configure code sniffer under Languages & Frameworks -> PHP -> Code Sniffer
- Go to Editor -> Inspections -> PHP Code sniffer, refresh the standards and select Symfony3RRoek
Customizations
The following adjustments have been made to the original standard:
In Sniff/WhiteSpace/AssignmentSpacingSniff:
- Added an exception for
declare(strict_types=1);
to comply with PSR-12
In Sniff/WhiteSpace/FunctionalClosingBraceSniff:
- copied from Squiz and adapted to have no blank line at the end of a function
In Sniff/Commenting/FunctionCommentSniff:
- check for 1 blank line above a docblock
- don't check docblocks for test and setUp methods (PHPunit, would be blank)
- do check protected and private methods for docblocks
In Sniff/NamingConventions/ValidClassNameSniff
- remove the abstract class name rule
In ruleset.xml
- Disabled the class comment rule
- Changed the concatenation spacing rule, for readability, to require 1 space around concatenation dot, instead of no spaces as the Symfony standard requires.
- Re-enabled the blank line check from superfluousWhitespace (disabled in PSR-2)