brandembassy / coding-standard
Brand Embassy Coding Standard
Installs: 228 915
Dependents: 16
Suggesters: 0
Security: 0
Stars: 2
Watchers: 11
Forks: 0
Open Issues: 6
Type:phpcodesniffer-standard
Requires
- php: >=8.1
- composer-runtime-api: ^2.2
- dealerdirect/phpcodesniffer-composer-installer: ^0.5 || ^0.7 || ^1.0
- phpstan/phpstan: ^1.11.6
- phpstan/phpstan-mockery: ^1.1
- phpstan/phpstan-nette: ^1.3.0
- phpstan/phpstan-phpunit: ^1.4.0
- phpstan/phpstan-strict-rules: ^1.6.0
- rector/rector: ^1.2.0
- slevomat/coding-standard: ^8.15.0
- squizlabs/php_codesniffer: ^3.9.2
- symplify/easy-coding-standard: ^12.1.14
- tomasvotruba/cognitive-complexity: ^0.2.3
Requires (Dev)
- marc-mabe/php-enum: ^v3.2.0
- mockery/mockery: ^1.5
- nette/utils: ^v4.0.5
- phpunit/phpunit: ^10.5
- roave/security-advisories: dev-latest
Conflicts
- dev-master
- 13.0
- 12.1.0
- 12.0.0
- 11.6
- 11.5
- 11.4.1
- 11.4.0
- 11.3.0
- 11.2.x-dev
- 11.2.2
- 11.2.1
- 11.2.0
- 11.1.0
- 11.0.0
- 10.1
- 10.0.0
- 10.0.0-beta
- 9.x-dev
- 9.0.0
- 8.10.1
- 8.10
- 8.9
- 8.8
- 8.7
- 8.6
- 8.5
- 8.4.1
- 8.4
- 8.3
- 8.2
- 8.1.5
- 8.1.4
- 8.1.3
- 8.1.2
- 8.1.1
- 8.1
- 8.0
- 7.3
- 7.2
- 7.1.1
- 7.1
- 7.0.0
- 6.x-dev
- 6.3.2
- 6.3.1
- 6.3
- 6.2
- 6.1
- 6.0.2
- 6.0.1
- 6.0.0
- 5.3.2
- 5.3.1
- 5.3
- 5.2
- 5.1
- 5.0
- 4.0
- 3.2
- 3.1.1
- 3.1
- 3.0
- 2.1.1
- 2.1.0
- 2.0.1
- 2.0
- 1.2.0
- 1.1.0
- 1.0.0
- dev-DE-113576-mabeEnum
- dev-DE-63904-add-rector-support
- dev-php-version-requirement-fix
- dev-update-slevomat-and-phpstan
- dev-de-31287
- dev-entity-not-final-rule
- dev-long-exception-variable-sniff
- dev-php-7-4-sniffs
- dev-all-php-keywords-lowercase
- dev-upgrate_phpstan
This package is auto-updated.
Last update: 2024-11-22 13:00:33 UTC
README
- The PHP_CodeSniffer and cs-fixer rules to check that repositories are following the unified coding standard for Brand Embassy projects.
- The PHPStan default configuration file.
- PhpStorm code style and inspections (with Php Inspections (EA Extended) plugin) configuration files.
Standards
For full reference of enforcements, go through default-ecs.php
where each sniff / fixer deviating from default set lists is briefly described.
@TODO list of important sniffs
Skippable sniffs / fixers
Skipping of sniffs / fixers in general or for particular files should be configured in the ecs.php
of your project. This file should leverage the default-ecs.php
as the default configuration, but it expected that you will make adjustments to fit your project needs.
Installation
You can install the Brand Embassy Coding Standard as a composer dependency to your project:
$ composer require --dev brandembassy/coding-standard
ECS
You can run ecs with this command (without performing automatic fixes):
$ ./vendor/bin/ecs check --ansi
Or with automatic fixes:
$ ./vendor/bin/ecs check --ansi --fix
You can use the --clear-cache
option to clear the cache before applying the fixers and sniffers:
$ ./vendor/bin/ecs check --ansi --fix --clear-cache
PHPStan
- includes phpstan-strict-rules extension
- includes phpstan-nette extension
- includes max level configuration by default
To use default configuration include default-phpstan.neon in your project's PHPStan config:
includes: - vendor/brandembassy/coding-standard/integration-phpstan.neon
Rector
To use default configuration require default-rector.php in your project's Rector config:
$rectorConfigBuilder = RectorConfig::configure(); $defaultRectorConfigurationSetup = require __DIR__ . '/vendor/brandembassy/coding-standard/default-rector.php'; $defaultSkipList = $defaultRectorConfigurationSetup($rectorConfigBuilder); // You can skip unwanted rules here $skipList = array_merge( $defaultSkipList, [ '*/__fixtures__/*', NewlineAfterStatementRector::class, // might conflict with ECS ], ); // You can override/append to the default configuration here $rectorConfigBuilder ->withPHPStanConfigs([__DIR__ . '/phpstan.neon']) ->withCache('./var/temp/rector', FileCacheStorage::class) ->withSkip($skipList); return $rectorConfigBuilder;
⚠️ Tests for Rector rules need to run in a separate process, because Rector and PHPStan use different versions of php-parser. See explanation here staabm/zf-select-strip#8. Another way would be to run them in a separate testsuite, but then we run into problems with code-coverage.
PhpStorm
This project contains inspections and code style configurations for PhpStorm.
BrandEmbassyCodeStyle.xml
BrandEmbassyInspections.xml
Importing these configurations reduces number of errors in phpcs
check before committing.
Versioning
This library follows semantic versioning, and additions to the code ruleset are only performed in major releases.
Testing
@TODO: inspiration - https://github.com/doctrine/coding-standard/tree/master/tests
If you are contributing to the Brand Embassy Coding Standard and want to test your contribution, you just need to execute PHPCS with the tests folder and ensure it matches the expected report:
$ ./vendor/bin/phpcs tests/input --report=summary --report-file=phpcs.log; diff tests/expected_report.txt phpcs.log