etsglobal / php-static-analysis
Static analysis tools configuration for PHP projects
Installs: 16 191
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 16
Forks: 0
Open Issues: 2
Type:phpcodesniffer-standard
Requires
- php: ^8.2
- jangregor/phpstan-prophecy: ^1.0
- pdepend/pdepend: ^2.14
- phpmd/phpmd: ^2.12
- phpspec/prophecy-phpunit: ^2.0
- phpstan/phpstan: ^1.8
- phpstan/phpstan-phpunit: ^1.1
- phpunit/phpunit: ^9.6
- sebastian/phpcpd: ^6.0.3
- slevomat/coding-standard: ^8.12
- squizlabs/php_codesniffer: ^3.7
README
This repository contains the base configuration for static analysis tools used by ETSGlobal PHP applications.
It includes:
- PHP_CodeSniffer configuration and custom sniffs
- PHP Mess Detector configuration
- PHPStan configuration
Installation
Using composer:
composer require etsglobal/php-static-analysis --dev
It will install squizlabs/php_codesniffer
by default, but you may install other optional tools manually:
composer require phpmd/phpmd phpstan/phpstan --dev
Usage
PHP_CodeSniffer
In your project root directory, add a phpcs.xml
file with the following contents:
<?xml version="1.0"?> <ruleset name="ETSGlobal Coding Standard" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../vendor/squizlabs/php_codesniffer/phpcs.xsd"> <rule ref="./vendor/etsglobal/php-static-analysis/lib/phpcs/phpcs.xml" /> </ruleset>
Then, run it with:
vendor/bin/phpcs src
If needed, you can exclude some rules by adding exceptions to your phpcs.xml
:
... <rule ref="SlevomatCodingStandard.Functions.TrailingCommaInCall"> <!-- Ignore missing trailing commas in multiline function calls --> <exclude name="SlevomatCodingStandard.Functions.TrailingCommaInCall.MissingTrailingComma"/> </rule> ...
PHP Mess Detector
First, make sure you have the phpmd/phpmd
package installed:
composer require phpmd/phpmd --dev
Then, in your project root directory, add a phpmd.xml
file with the following contents:
<?xml version="1.0"?> <ruleset name="ETSGlobal ruleset" xmlns="http://pmd.sf.net/ruleset/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd" xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd"> <description> ETSGlobal ruleset </description> <rule ref="./vendor/etsglobal/php-static-analysis/lib/phpmd/phpmd.xml"/> </ruleset>
Now run phpmd:
vendor/bin/phpmd src text phpmd.xml
PHPStan
First, make sure you have the phpstan/phpstan
package installed:
composer require phpstan/phpstan --dev
Then, in your project root directory, add a phpstan.neon
file with the following contents:
includes: - vendor/etsglobal/php-static-analysis/lib/phpstan/phpstan.neon
You can now run phpstan:
vendor/bin/phpstan analyse --level=max src