PHP Festi Coding Standard

The shared quality toolchain for Festi PHP projects, installed as one Composer dev dependency: festi-team/coding-standard.

What you get Tool Looks at
The Festi coding standard PHP_CodeSniffer style, naming, docblocks, complexity of one function
Class-design limits PHPMD size and coupling of a class, parameter counts
A Phan baseline and Festi plugins Phan types, plane separation, SQL injection, disabled guards
festi-quality all of the above, plus the SonarQube quality gate, issues, hotspots and new uncovered lines one summary for a project, some paths, or a change; the report of the sonar job
festi-phpcs-diff PHP_CodeSniffer the merge request gate: only the lines a branch changed
Reusable GitLab CI jobs the same checks in a pipeline

The same rules run in every project's pipeline and in the agent_festireview review bot, so there is one source of truth.

Quick start

composer require --dev festi-team/coding-standard

Allow the Composer plugin that registers the standard with phpcs, in the project's composer.json:

"config": {
    "allow-plugins": {
        "dealerdirect/phpcodesniffer-composer-installer": true
    }
}

Then, from the project root:

vendor/bin/festi-quality                  # the whole project
vendor/bin/festi-quality src tests/Unit   # these files and directories
vendor/bin/festi-quality --diff           # only what this branch changed
vendor/bin/festi-quality --diff --list    # ... with every issue and its line
vendor/bin/festi-quality --diff --strict  # ... and fail when there is one
Festi quality summary
Scope: lines changed since origin/develop, in 3 file(s)

  phpcs  2 issues     2 errors, 0 warnings, 1 auto-fixable
  phpmd  0 issues
  phan   0 issues
  sonar  SKIPPED      set SONAR_HOST_URL and SONAR_TOKEN to read com.festi:cli

phpcs by rule
       1  Generic.Arrays.DisallowLongArraySyntax.Found
       1  Festi.NamingConventions.EntityIdNaming.VariableIdNaming

A Festi project is expected to have all three set up: the coding standard, a Phan configuration and a SonarQube project. Installation covers each.

In the sonar job

The sonar job of a project calls festi-quality after sonar-scanner:

sonar:
  stage: test
  variables:
    GIT_DEPTH: 0
  script:
    - composer install --no-interaction --prefer-dist --no-progress
    - sonar-scanner
    - vendor/bin/festi-quality --only=sonar

It waits until the server has processed the scan of the job, then prints the quality gate with each condition, the open issues, the security hotspots to review and the files with new uncovered lines. A red gate fails the job. The token comes only from the SONAR_TOKEN CI variable, and the command does not print it. GitLab CI has the details and a form with two jobs.

Documentation

Read To
Installation install the package, set up Phan and SonarQube, migrate an existing project
Usage run the checks: the whole project, paths, or a change; options, exit codes, the tools one by one
GitLab CI add the shipped jobs to a pipeline
Rules see what each rule asks for, with examples
Configuration change a limit, switch a rule off, tune a Phan plugin, adopt a rule on a codebase with a backlog
Extending add a sniff, a PHPMD rule, a Phan plugin or a tool to festi-quality; test and release it

Requirements

Constraint
PHP >=8.1
squizlabs/php_codesniffer ^3.13.6 \|\| ^4.0.2
phan/phan ^6.0
phpmd/phpmd ^3.0
pdepend/pdepend ^3.0
slevomat/coding-standard ^8.22

All of them come with the package; a project does not require them itself.