PHPackages                             atournayre/phpstan-elegant-object - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. atournayre/phpstan-elegant-object

ActivePhpstan-extension[Testing &amp; Quality](/categories/testing)

atournayre/phpstan-elegant-object
=================================

Custom PHPStan rules for enforcing elegant object design

1.0.0(9mo ago)111.7k[1 issues](https://github.com/atournayre/phpstan-elegant-object/issues)2MITPHPPHP &gt;=8.2.22

Since Mar 19Pushed 9mo ago1 watchersCompare

[ Source](https://github.com/atournayre/phpstan-elegant-object)[ Packagist](https://packagist.org/packages/atournayre/phpstan-elegant-object)[ RSS](/packages/atournayre-phpstan-elegant-object/feed)WikiDiscussions main Synced 3w ago

READMEChangelog (4)Dependencies (4)Versions (6)Used By (2)

> This extension is a work in progress. Use at your own risk.

PHPStan Elegant Object Rules
============================

[](#phpstan-elegant-object-rules)

This PHPStan extension adds custom rules to encourage and validate elegant object design principles in your PHP code.

It's based on [Yegor Bugayenko](https://github.com/yegor256)'s [books](https://www.yegor256.com/books.html) :

- Elegant Objects (Volume 1)
- Elegant Objects (Volume 2)

Installation
------------

[](#installation)

```
composer require --dev atournayre/phpstan-elegant-object
```

Configuration
-------------

[](#configuration)

Include the extension in your phpstan.neon file:

```
# Include the extension config if you want extra strict rules
includes:
    - vendor/atournayre/phpstan-elegant-object/phpstan.neon
```

> It is recommended to configure each rule separately.

Available Rules
---------------

[](#available-rules)

See [configuration](docs/configuration.md) for a list of available rules.

Creating Custom Rules
---------------------

[](#creating-custom-rules)

To create a new rule:

1. Create a class in the `src/Analyzer/` folder that implements `Atournayre\PHPStan\ElegantObject\Analyzer\RuleAnalyzer`
2. Define the node type to analyze with `getNodeType()`
3. Override `shouldSkipAnalysis()` if necessary
4. Implement your analysis logic in `analyze()`
5. Create a class in the `src/Rules/` folder that extends `Atournayre\PHPStan\ElegantObject\Rules\ComposableRule` (see existing rules for examples)
6. Register your rule in `phpstan.neon`

Tests
-----

[](#tests)

To run the tests:

```
vendor/bin/phpunit
```

Rules
-----

[](#rules)

From the book:

- Never use -er names (chapter 1.1)
- Keep constructors code-free (chapter 1.3)
- Always use interface (chapter 2.3)
- Don't use public constant (chapter 2.5)
- Be immutable (chapter 2.6)
- Keep interfaces short (chapter 2.9)
- Expose fewer than 5 public methods (chapter 3.1)
- Don't use static methods (chapter 3.2)
- Never accept null arguments (chapter 3.3)
- Never use getters and setters (chapter 3.5)
- Don't use new outside of secondary constructors (chapter 3.6)
- Avoid type introspection and casting (chapter 3.7)
- Never return Null (chapter 4.1)
- Throw only checked exceptions (chapter 4.2)
- Be either final or abstract (chapter 4.3)
- Private static literals (chapter 5.4)

Other:

- All properties must be private
- Constructor objects only

###  Health Score

39

—

LowBetter than 85% of packages

Maintenance54

Moderate activity, may be stable

Popularity26

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~56 days

Total

4

Last Release

290d ago

Major Versions

0.2.0 → 1.0.02025-09-06

### Community

Maintainers

![](https://www.gravatar.com/avatar/be702ea3d10de6d97d83c32866fc9cfe1830a055e7f8b685c8434ccad40416c1?d=identicon)[atournayre](/maintainers/atournayre)

---

Top Contributors

[![atournayre](https://avatars.githubusercontent.com/u/4262077?v=4)](https://github.com/atournayre "atournayre (26 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/atournayre-phpstan-elegant-object/health.svg)

```
[![Health](https://phpackages.com/badges/atournayre-phpstan-elegant-object/health.svg)](https://phpackages.com/packages/atournayre-phpstan-elegant-object)
```

###  Alternatives

[larastan/larastan

Larastan - Discover bugs in your code without running it. A phpstan/phpstan extension for Laravel

6.4k51.0M7.6k](/packages/larastan-larastan)[phpstan/phpstan-symfony

Symfony Framework extensions and rules for PHPStan

79173.3M2.0k](/packages/phpstan-phpstan-symfony)[phpstan/phpstan-doctrine

Doctrine extensions for PHPStan

67070.7M1.3k](/packages/phpstan-phpstan-doctrine)[shipmonk/dead-code-detector

Dead code detector to find unused PHP code via PHPStan extension. Can automatically remove dead PHP code. Supports libraries like Symfony, Doctrine, PHPUnit etc. Detects dead cycles. Can detect dead code that is tested.

4813.1M82](/packages/shipmonk-dead-code-detector)[spaze/phpstan-disallowed-calls

PHPStan rules to detect disallowed method &amp; function calls, constant, namespace, attribute, property &amp; superglobal usages, with powerful rules to re-allow a call or a usage in places where it should be allowed.

33321.8M508](/packages/spaze-phpstan-disallowed-calls)[mglaman/phpstan-drupal

Drupal extension and rules for PHPStan

20830.6M167](/packages/mglaman-phpstan-drupal)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
