pixelfederation / coding-standards
Standardized PHPCS sniffs for backend developers.
Installs: 76 863
Dependents: 4
Suggesters: 0
Security: 0
Stars: 2
Watchers: 5
Forks: 0
Open Issues: 1
Type:phpcodesniffer-standard
pkg:composer/pixelfederation/coding-standards
Requires
- php: ^8.3
- slevomat/coding-standard: ^8.24
- squizlabs/php_codesniffer: ^4.0
Requires (Dev)
- ext-dom: *
- ext-libxml: *
- ergebnis/composer-normalize: ^2.45
- friendsofphp/php-cs-fixer: ^3.89
- nikic/php-parser: ^5.6
- php-parallel-lint/php-parallel-lint: ^1.4
- phpmd/phpmd: ^2.15
- phpro/grumphp: ^2.17
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^12.5
README
This package provides PHPCS rule set for coding standards in Pixel Federation. It should be included into each project maintained by Pixel Federation that uses PHP Code Sniffer PHPCS.
Migration from v4 to v4.1.0
Generic ruleset was removed. Now there are only rulesets for specific PHP versions.
Replace (in your ruleset) reference to file
vendor/pixelfederation/coding-standards/phpcs.ruleset.xml
with
vendor/pixelfederation/coding-standards/phpcs.ruleset.84.xml
for PHP 8.4.
How to use
Install composer dependencies
composer require --dev pixelfederation/coding-standards:^5.0
Supported versions
For each php version there are 2 versions of the ruleset. One for DDD projects and one for Non-DDD projects.
For example for PHP 8.4:
vendor/pixelfederation/coding-standards/phpcs.ruleset.84.xml
OR
vendor/pixelfederation/coding-standards/phpcs.ruleset.84.non-ddd.xml
Ruleset creation
Create a file named phpcs.ruleset.xml in the root folder of your project with the following content:
<?xml version="1.0"?> <ruleset name="PixelFederation"> <description>PixelFederation rule set.</description> <exclude-pattern>tests/</exclude-pattern> <rule ref="vendor/pixelfederation/coding-standards/phpcs.ruleset.84.xml"> <!-- Insert version for your php version --> <!-- You can exclude some rules here --> <exclude name="SlevomatCodingStandard.Files.FunctionLength"/> </rule> </ruleset>
Running checks
In your project directory run this command:
vendor/bin/phpcs --standard=phpcs.ruleset.xml src
Automatically fixing errors
In your project directory run this command:
vendor/bin/phpcbf --standard=phpcs.ruleset.xml src
Additional links
Sniffs documentation for slevomat coding standards are here: https://github.com/slevomat/coding-standard
GrumPHP
Tasks
Installation
# grumphp.yml grumphp: extensions: - PixelFederation\CodingStandards\GrumPHP\ExtensionLoader
Doctrine ORM Mapping Validation
# grumphp.yml grumphp: tasks: doctrine_schema_validate: skip_mapping: false skip_sync: false skip_property_types: false em: default triggered_by: ['php', 'xml', 'yml']
For multiple entity managers you can specify the entity manager to be used:
# grumphp.yml grumphp: tasks: doctrine_schema_validate_application: em: application metadata: task: doctrine_schema_validate doctrine_schema_validate_reporting: em: reporting metadata: task: doctrine_schema_validate
console_path
Default: 'bin/console'
With this parameter you can set the path of the console to be used.
skip_mapping
Default: false
With this parameter you can skip the mapping validation check.
skip_sync
Default: false
With this parameter you can skip checking if the mapping is in sync with the database.
triggered_by
Default: [php, xml, yml]
This is a list of extensions that should trigger the Doctrine task.
em
Default: null
Require doctrine/orm >= 3.0.
Specify the entity manager to be used. If not set, the default entity manager will be used.
skip_property_types
Default: null
Require doctrine/orm >= 3.0.
With this parameter you can skip checking if property types match the Doctrine types.
Composer Install Check
# grumphp.yml grumphp: tasks: composer_install_check: script: './vendor/pixelfederation/coding-standards/bin/composer_install_check.sh', ignore_patterns: [] triggered_by: ['php', 'yml', 'yaml', 'xml'] whitelist_patterns: [] metadata: priority: 900
script
Default: './bin/composer_install_check.sh'
Path to check script.
ignore_patterns
Default: []
This is a list of patterns that will be ignored by phpcs. With this option you can skip files like tests. Leave this option blank to run phpcs for every php file.
triggered_by
Default: ['php', 'yml', 'yaml', 'xml']
This is a list of extensions to be sniffed.
whitelist_patterns
Default: []
This is a list of regex patterns that will filter files to validate. With this option you can skip files like tests. This option is used in relation with the parameter triggered_by.
PhpMd Extended
Extends the default PhpMd task and splits the files into smaller chunks to prevent the Argument list too long error.
Config
The task lives under the phpmd_extended namespace and has following configurable parameters:
# grumphp.yml grumphp: tasks: phpmd_extended: whitelist_patterns: [] exclude: [] report_format: text ruleset: ['cleancode', 'codesize', 'naming'] triggered_by: ['php'] chunks_size: 1000
chunk_size
Default: 1000
This parameter defines how many files will be checked in one execution of phpmd. This can help with performance on large codebases.
PHPStan Extended
Extends the default PHPStan task and splits the files into smaller chunks to prevent the Argument list too long error.
Config
The task lives under the phpstan_extended namespace and has following configurable parameters:
# grumphp.yml grumphp: tasks: phpstan_extended: autoload_file: ~ chunk_size: 1000 configuration: ~ level: null force_patterns: [] ignore_patterns: [] triggered_by: ['php'] memory_limit: "-1" use_grumphp_paths: true
chunk_size
Default: 1000
This parameter defines how many files will be checked in one execution of phpstan. This can help with performance on large codebases.
XmlLint Extended
Extends the default XmlLint task with strict schema validation.
Require ext-dom and ext-libxml extensions.
Config
It lives under the xmllint_extended namespace and has following configurable parameters:
# grumphp.yml grumphp: tasks: xmllint_extended: ignore_patterns: [] load_from_net: false x_include: false dtd_validation: false scheme_validation: false triggered_by: ['xml']