etsglobal / php-static-analysis
Static analysis tools configuration for PHP projects
This package's canonical repository appears to be gone and the package has been frozen as a result.
Installs: 19 751
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 14
Forks: 0
Open Issues: 0
Type:phpcodesniffer-standard
Requires
- php: ^8.3
- codeception/codeception: ^5.1
- codeception/module-amqp: ^3.0
- codeception/module-apc: ^3.0
- codeception/module-asserts: ^3.0
- codeception/module-filesystem: *
- codeception/module-mongodb: ^3.0
- codeception/module-rest: ^3.0
- codeception/module-symfony: ^3.3
- jangregor/phpstan-prophecy: ^1.0
- mcustiel/phiremock: ^2.1
- mcustiel/phiremock-client: ^1.2
- mcustiel/phiremock-codeception-extension: ^3.0
- mcustiel/phiremock-codeception-module: ^2.0
- phpmd/phpmd: ^2.15
- phpspec/prophecy-phpunit: ^2.1
- phpstan/phpstan: ^1.10
- phpstan/phpstan-phpunit: ^1.3
- phpunit/phpunit: ^11.0 || ^12.0
- predis/predis: ^2.0
- sebastian/comparator: ^6.0
- slevomat/coding-standard: ^8.14
- squizlabs/php_codesniffer: ^3.8
Requires (Dev)
- symfony/cache: ^7.0
This package is auto-updated.
Last update: 2024-11-22 12:28:56 UTC
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