eventjet/coding-standard

Eventjet Coding Standard

Installs: 18 330

Dependents: 21

Suggesters: 0

Security: 0

Stars: 0

Watchers: 2

Forks: 0

Open Issues: 0

Type:phpcodesniffer-standard

3.7.1 2022-02-17 12:50 UTC

This package is auto-updated.

Last update: 2022-04-17 13:07:25 UTC


README

Basic Usage:

Add the following phpcs.xml file to your project's root:

<?xml version="1.0"?>
<ruleset>
    <rule ref="Eventjet"/>

    <file>src</file>
    <file>tests</file>
</ruleset>

More strict rules:

There is also a more strict ruleset which forces type hints and return types to be set.

This sniff can be problematic: If you implement interfaces or have your own interfaces which don't have parameter type hints and return types set or if you are on legacy code, enforcing this sniff would lead to a BC break. This sniff is also set to phpcs-only, so phpcbf won't fix errors automatically.

To use this ruleset, just use the use the corresponding rule name in your phpcs rule ref instead of the default one:

<?xml version="1.0"?>
<ruleset>
    <rule ref="EventjetStrict"/>

    <file>src</file>
    <file>tests</file>
</ruleset>

Excluding sniffs:

For certain files:

To exclude a sniff for a certain set of files, reference the rule explicitly and add an exclude pattern:

<rule ref="SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint">
    <exclude-pattern>*Interface.php</exclude-pattern>
</rule>

Suppressing sniffs locally

To suppress a sniff directly in the code, use the @phpcsSuppress annotation:

/**
 * @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint
 * @param int $bar
 */
public function foo($bar = 0): int
{
}

More info on this can be found here.

Exclude a whole sniff:

It is also possible to exclude a sniff completely:

<?xml version="1.0"?>
<ruleset>
    <rule ref="Eventjet">
        <exclude name="SlevomatCodingStandard.Classes.ClassConstantVisibility"/>
    </rule>

    <file>src</file>
    <file>tests</file>
</ruleset>