interaction-design-foundation / coding-standard
IxDF Standard for PHP_CodeSniffer complements Consistence Coding Standard by providing sniffs with additional checks.
Installs: 56 289
Dependents: 8
Suggesters: 0
Security: 0
Stars: 7
Watchers: 7
Forks: 0
Open Issues: 2
Type:phpcodesniffer-standard
Requires
- php: ^8.2
- dealerdirect/phpcodesniffer-composer-installer: ^1.0
- slevomat/coding-standard: ^8.15
- squizlabs/php_codesniffer: ^3.10
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.59
- phpunit/phpunit: ^10.5
- vimeo/psalm: ^5.25
README
IxDF Coding Standard for Laravel
An opinionated ruleset focused on strict types. Suitable for both applications and packages.
Installation
- Install the package via composer by running:
composer require --dev interaction-design-foundation/coding-standard
- Add composer scripts into your
composer.json
:
"scripts": { "cs:check": "phpcs -p -s --colors --report-full --report-summary", "cs:fix": "phpcbf -p --colors" }
- Create file
phpcs.xml
on base path of your repository with content
<?xml version="1.0"?> <ruleset name="My Coding Standard"> <!-- Include all rules from the IxDF Coding Standard --> <rule ref="IxDFCodingStandard"/> <!-- Paths to check --> <file>app</file> <file>config</file> <file>database</file> <file>lang</file> <file>routes</file> <file>tests</file> </ruleset>
Usage
- To run checks only:
composer cs:check
- To automatically fix many CS issues:
composer cs:fix
Ignoring parts of a File
Disable parts of a file:
$xmlPackage = new XMLPackage; // phpcs:disable $xmlPackage['error_code'] = get_default_error_code_value(); $xmlPackage->send(); // phpcs:enable
Disable a specific rule:
// phpcs:disable Generic.Commenting.Todo.Found $xmlPackage = new XMLPackage; $xmlPackage['error_code'] = get_default_error_code_value(); // TODO: Add an error message here. $xmlPackage->send(); // phpcs:enable
Ignore a specific violation:
$xmlPackage = new XMLPackage; $xmlPackage['error_code'] = get_default_error_code_value(); // phpcs:ignore Generic.Commenting.Todo.Found // TODO: Add an error message here. $xmlPackage->send();
Development
Versioning
New rules or Sniffs may not be introduced in minor or bugfix releases and should always be based on the develop branch and queued for the next major release, unless considered a bugfix for existing rules.
Reference
Rules can be added, excluded or tweaked locally, depending on your preferences. More information on how to do this can be found here:
- Coding Standard Tutorial
- Configuration Options
- Selectively Applying Rules
- Customisable Sniff Properties
- Other coding standards (inspiring us):