Search by

chez14 / phpcs

chez14

PHP Code Style for chez14 Projects

Package info

gitlab.com/chez14/phpcs

Issues

pkg:composer/chez14/phpcs

Statistics

Installs: 731

Dependents: 2

Suggesters: 0

Stars: 0

v1.0.5 2026-10-04 17:19 UTC

This package is auto-updated.

Last update: 2026-10-04 10:19:39 UTC


README

The code style standard based on PSR12 with additional extras that chez14 expect contributors and maintainer to fill in.

Just to make sure everyone write clean documentation for the project they wanted.

Additional Ruleset:

  • PEAR.Commenting.FunctionComment \ Make sure to document functions. This will help people that have their IntelliSense enabled on their IDE.

  • PEAR.Commenting.InlineComment \ Disable perl style commenting. To chez14, this looks distracting.

  • Squiz.PHP.DisallowInlineIf \ Bans ternary expressions, both $a ? $b : $c and the short form $a ?: $b. Use an early return, if/else or match instead. The null coalescing operator (??) and the nullsafe operator (?->) are still allowed.

Working with PHP-CS-Fixer (@PER-CS)

Formatting is owned by PHP-CS-Fixer with the @PER-CS rule set; phpcs with this standard only enforces rules (documentation, no ternaries, naming, ...). The two tools must never disagree, so the ruleset excludes the PSR12 sniffs that report code PHP-CS-Fixer produces:

Excluded sniffWhy
Squiz.Functions.MultiLineFunctionDeclaration.BraceOnSameLinePER-CS keeps empty bodies on the declaration line, e.g. promoted constructors ) {}.
Squiz.WhiteSpace.ScopeClosingBrace.ContentBeforeSame {} empty body.
PSR12.Operators.OperatorSpacing.NoSpaceBefore / NoSpaceAfterPER-CS writes multi-catch types without spaces: catch (A\|B $e).

Run PHP-CS-Fixer first (php-cs-fixer fix), then phpcs. PEAR.Commenting.FunctionComment is kept as is: it works with promoted constructor parameters, variadics and generic types such as list<Node>.

Known limitation: PHP_CodeSniffer (3.13 and 4.0) does not understand PHP 8.4 property hooks yet, so the PSR2 property sniffs may report hooked properties.

Supported PHP_CodeSniffer versions: ^3.13 || ^4.0.

Installation

  • Make sure you have installed CodeSniffer: https://github.com/squizlabs/PHP_CodeSniffer

  • Add the coding standard to your project.

    composer req --dev chez14/phpcs squizlabs/php_codesniffer
    
  • Make phpcs use this standard:

  • Recommended project setup (formatting by PHP-CS-Fixer, rules by phpcs):

    composer req --dev friendsofphp/php-cs-fixer chez14/phpcs squizlabs/php_codesniffer
    

    phpcs.xml.dist:

    <?xml version="1.0"?>
    <ruleset name="my-project" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd">
      <file>src</file>
      <file>tests</file>
    
      <arg name="colors"/>
      <arg value="s"/>
    
      <rule ref="vendor/chez14/phpcs/src/CHEZ14Standards/ruleset.xml"/>
    
      <!-- Optional: tests do not need function docblocks. -->
      <rule ref="PEAR.Commenting.FunctionComment">
        <exclude-pattern>tests/*</exclude-pattern>
      </rule>
    </ruleset>
    

    .php-cs-fixer.dist.php:

    <?php
    
    declare(strict_types=1);
    
    return (new PhpCsFixer\Config())
        ->setRiskyAllowed(true)
        ->setRules(['@PER-CS' => true, 'declare_strict_types' => true])
        ->setFinder(PhpCsFixer\Finder::create()->in([__DIR__ . '/src', __DIR__ . '/tests']));
    

    composer.json scripts:

    {
        "scripts": {
            "lint": ["php-cs-fixer fix --dry-run --diff", "phpcs"],
            "lint:fix": "php-cs-fixer fix"
        }
    }
    
  • Add the code sniffer script to the Composer.

    {
        "script": {
          "style": "phpcs src/",
          "style:fix": "phpcbf src/"
        }
    }
    

License

MIT.