Search by

lifephp / coding-standards

Shared PHP_CodeSniffer standard for lifephp packages: orisai/coding-standard tuned to PSR/PER plus a few custom sniffs.

Maintainers

Package info

gitlab.com/life9/php-life/coding-standards

Issues

Type:phpcodesniffer-standard

pkg:composer/lifephp/coding-standards

Transparency log

Statistics

Installs: 9

Dependents: 3

Suggesters: 0

Stars: 0

v2.0.0 2026-09-03 23:26 UTC

This package is auto-updated.

Last update: 2026-09-03 21:28:18 UTC


README

GitLab Pipeline Status GitLab Release Packagist Version PHPStan Level Packagist Downloads Packagist Monthly Downloads Packagist Stars GitLab Issues Packagist License Packagist Dependency Version

Quickstart

Shared PHP_CodeSniffer 4.x standard for lifephp packages, built on slevomat/coding-standard. Its baseline sniff selection (LifephpCodingStandard/base.ruleset.xml) is adopted from the now-unmaintained orisai/coding-standard; on top of that it re-tunes towards PSR / PER Coding Style (4-space indent, declare(strict_types=1) on its own line, ?T nullable shorthand, ): Type { for multi-line signatures), adds hard size limits, and ships a couple of custom sniffs.

Installation

composer require --dev lifephp/coding-standards

slevomat/coding-standard comes with it. dealerdirect/phpcodesniffer-composer-installer registers this standard automatically.

Wiring it into a project

phpcs.xml — one <rule ref> by path to LifephpCodingStandard/ruleset.xml. It bundles the baseline itself, so there is nothing to include before it:

<?xml version="1.0"?>
<ruleset>
    <arg name="basepath" value="./"/>

    <rule ref="./vendor/lifephp/coding-standards/LifephpCodingStandard/ruleset.xml"/>

    <!-- your PSR-4 roots -->
    <rule ref="SlevomatCodingStandard.Files.TypeNameMatchesFileName">
        <properties>
            <property name="rootNamespaces" type="array">
                <element key="src" value="Acme\Thing"/>
                <element key="tests" value="Acme\Thing\Tests"/>
            </property>
        </properties>
    </rule>
</ruleset>

Reference it by that path, not <rule ref="LifephpCodingStandard"/> — the bare standard name resolves for --standard= and for dotted sniff refs, but not for a <rule ref> inside a consumer's ruleset, because the composer install registers the package root (vendor/lifephp/coding-standards), one level above the LifephpCodingStandard/ directory.

Advisory size limits

The blocking limits (method 40 lines, class 400) are in the ruleset above. Softer limits (method 20, class 200) that only warn ship as a separate ruleset — run them as a non-failing pass:

// composer.json scripts
"phpcs:metrics": "phpcs --standard=vendor/lifephp/coding-standards/metrics.xml --runtime-set ignore_warnings_on_exit 1 src tests"

Sniffs

Two sniffs together own function/method/closure opening-brace placement. The orisai/PSR sniffs on this topic are disabled by the ruleset because they conflict with this convention (and with each other).

BodyOpening brace
empty) { } on the signature line
non-empty, single-line sigown line, at the signature's indent
non-empty, multi-line sig): Type { (hugs, PSR-12 §4.5)
public function __construct(
    private readonly Foo $foo,
) { }

public function make(): Foo
{
    return new Foo();
}

public function build(
    int $a,
    int $b,
): int {
    return $a + $b;
}

LifephpCodingStandard.Functions.EmptyFunctionBodyOnSameLine

Empty bodies () { }). Auto-fixable. A body with a comment is not "empty". Whether an empty body is allowed is another sniff's job (orisai's SlevomatCodingStandard.Functions.DisallowEmptyFunction).

PropertyDefaultEffect
spacing10 => {}, 1 => { } between braces

LifephpCodingStandard.Functions.FunctionOpeningBrace

Non-empty bodies: Allman for single-line signatures, hug for multi-line. Auto-fixable.

For AI coding agents

This package ships machine-readable usage instructions via the lifephp/composer-ai-instructions protocol — see ai/usage.md.

Development

This package is currently maintained by:

TonnyJe

Conclusion

This package is property of Antonín Jehlář © 2026