lifephp / phpstan-rules
Reusable generic PHPStan rules, starting with #[CreateBy] factory-only instantiation enforcement.
Package info
gitlab.com/life9/php-life/phpstan-rules
Type:phpstan-extension
pkg:composer/lifephp/phpstan-rules
Requires
- php: >=8.4
- phpstan/phpstan: ^2.1
Requires (Dev)
- lifephp/coding-standards: ^1.0
- phpunit/phpunit: ^12.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-09-01 20:43:29 UTC
README
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:
Conclusion
This package is property of Antonín Jehlář © 2026