Skip to content

QA - Add PHP_CodeSniffer (phpcs) dependency

detects violations of a defined set of coding standards.

documentation:

# install
composer require --dev "squizlabs/php_codesniffer"

# Show rules and coding standards
vendor/bin/phpcs -i  #  list of installed coding standards
vendor/bin/phpcs -e  #  list of rules used by .phpcs.xml config

# Check files based on .phpcs.xml config
vendor/bin/phpcs
vendor/bin/phpcs --report=source  # error summary
vendor/bin/phpcs --report=full    # all errors
vendor/bin/phpcs --report=diff    # printing a diff Report

# Check specific files and directories
vendor/bin/phpcs <dir>/<file>
vendor/bin/phpcs <dir>/*

# Check files with specific coding standard
vendor/bin/phpcs --standard=PSR12 src/*

# Automatically fix errors (that can be)
vendor/bin/phpcbf