Search by

lifephp / phpstan-rules

Reusable generic PHPStan rules, starting with #[CreateBy] factory-only instantiation enforcement.

Maintainers

Package info

gitlab.com/life9/php-life/phpstan-rules

Issues

Type:phpstan-extension

pkg:composer/lifephp/phpstan-rules

Transparency log

Statistics

Installs: 3

Dependents: 1

Suggesters: 0

Stars: 0

v1.0.0 2026-09-01 22:36 UTC

This package is auto-updated.

Last update: 2026-09-01 20:43:29 UTC


README

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

Quickstart

A growing collection of generic, reusable PHPStan rules. Every rule is opt-in — it only restricts code that explicitly asks for it, so requiring this package never produces new errors on its own.

Installation

composer require --dev lifephp/phpstan-rules phpstan/extension-installer

Allow phpstan/extension-installer to run (Composer will prompt, or add it explicitly):

{
    "config": {
        "allow-plugins": {
            "phpstan/extension-installer": true
        }
    }
}

phpstan/extension-installer auto-registers this package's rules — no manual includes: in your own phpstan.neon needed. Without it, add the include yourself:

includes:
    - vendor/lifephp/phpstan-rules/rules.neon

Rules

#[CreateBy(factory: ...)]

Restricts a class to being instantiated only from within one declared class/trait, or by any class implementing one declared interface:

use Lifephp\PHPStanRules\CreateBy\CreateBy;

#[CreateBy(factory: PaymentFactory::class)]
class Payment
{
}

class PaymentFactory
{
    public function create(): Payment
    {
        return new Payment(); // OK
    }
}

Full contract, including the interface-based match (for cases like Nette-generated factories) and how to fix a violation: ai/rules/create-by.md.

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