Code Sniffer

Edit on GitHub

To correspond to PSR-2 and additional standards, we integrated the well known PHPCodeSniffer.

Code Sniffer is a very powerful tool that helps to keep your code clean and prevent simple mistakes. The Sniffer can find all existing issues, and can also auto-fix the majority of them (when used with the -f option).

$ vendor/bin/console code:sniff:style

	// Fix fixable errors instead of just reporting
	$ vendor/bin/console code:sniff:style -f

	// Sniff a specific module in your project (looks into all application layers Zed, Yves, Client, ...)
	$ vendor/bin/console code:sniff:style -m Discount

	// Sniff a specific subfolder of your project
	$ vendor/bin/console code:sniff:style src/Pyz/Zed

	// Run a specific sniff only
	$ vendor/bin/console code:sniff:style ... -s Spryker.Commenting.FullyQualifiedClassNameInDocBlock

There are two levels of the Sniffer’s severity: Level 1 (normal, used by default) and Level 2 (strict). Level 2 was added to support an additional check of extra complexity. It is recommended to use it for the development of Core modules. A full list of the included sniffs can be found on GitHub.

	// Run code sniffer with Level 1
	console c:s:s -m Spryker.Development -l 1

	// Run code sniffer with Level 2
	console c:s:s -m Spryker.Development -l 2 -v
Tip

c:s:s can be used as short for code:sniff:style.

Additional options:

  • -v: Verbose output
  • -d: Dry-run, only output the command to be run

Remember to always commit your changes before executing this command!

Run –help or -h to get help about the usage of all available options.

See the Code Sniffer documentation for details and information on how to set it up for your CI system as a checking tool for each PR.