Skip to content

Latest commit

History

45 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Coding standards

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"?>
<rulesetname="PixelFederation">
<description>PixelFederation rule set.</description>
<exclude-pattern>tests/</exclude-pattern>
<ruleref="vendor/pixelfederation/coding-standards/phpcs.ruleset.84.xml"> <!-- Insert version for your php version --><!-- You can exclude some rules here -->
<excludename="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

Note: Custom tasks don’t work when using phpro/grumphp-shim (PHAR) with parallel.enabled: true due to class serialization limitations. If you need custom tasks, install GrumPHP via Composer.

Tasks

Installation

# grumphp.ymlgrumphp:
extensions:
- PixelFederation\CodingStandards\GrumPHP\ExtensionLoader

Doctrine ORM Mapping Validation

# grumphp.ymlgrumphp:
tasks:
doctrine_schema_validate:
skip_mapping: falseskip_sync: falseskip_property_types: falseem: defaulttriggered_by: ['php', 'xml', 'yml']

For multiple entity managers you can specify the entity manager to be used:

# grumphp.ymlgrumphp:
tasks:
doctrine_schema_validate_application:
em: applicationmetadata:
task: doctrine_schema_validatedoctrine_schema_validate_reporting:
em: reportingmetadata:
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.ymlgrumphp:
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.ymlgrumphp:
tasks:
phpmd_extended:
whitelist_patterns: []exclude: []report_format: textruleset: ['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.ymlgrumphp:
tasks:
phpstan_extended:
autoload_file: ~chunk_size: 1000configuration: ~level: nullforce_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.ymlgrumphp:
tasks:
xmllint_extended:
ignore_patterns: []load_from_net: falsex_include: falsedtd_validation: falsescheme_validation: falsetriggered_by: ['xml']

About

PHPCS rule set for coding standards in Pixel Federation

Topics

Resources

Stars

2 stars

Watchers

5 watching

Forks

Releases

Packages

Used by

Contributors

Languages