PHPackages                             phpnomad/phpstan-rules - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. phpnomad/phpstan-rules

ActivePhpstan-extension[Utility &amp; Helpers](/categories/utility)

phpnomad/phpstan-rules
======================

PHPStan rules for PHPNomad framework conventions

v1.0.0(1mo ago)01.5k1MITPHPPHP ^8.2CI passing

Since Apr 14Pushed 1mo agoCompare

[ Source](https://github.com/phpnomad/phpstan-rules)[ Packagist](https://packagist.org/packages/phpnomad/phpstan-rules)[ RSS](/packages/phpnomad-phpstan-rules/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependencies (3)Versions (2)Used By (1)

PHPNomad PHPStan Rules
======================

[](#phpnomad-phpstan-rules)

Custom [PHPStan](https://phpstan.org/) rules that enforce [PHPNomad](https://github.com/phpnomad) framework conventions.

These rules catch architectural anti-patterns at static analysis time, including models with inline serialization, service locator usage, raw SQL, singleton abuse, missing interface implementations, database scope violations, cache misuse, and more.

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

[](#installation)

```
composer require --dev phpnomad/phpstan-rules
```

If you use [phpstan/extension-installer](https://github.com/phpstan/extension-installer), the rules activate automatically.

Otherwise, add to your `phpstan.neon`:

```
includes:
    - vendor/phpnomad/phpstan-rules/extension.neon
```

Rules
-----

[](#rules)

### Models

[](#models)

IdentifierDescription`phpnomad.model.notFinal`Models implementing `DataModel` must be declared `final`.`phpnomad.model.setter`Models must not have setter methods (`set*`). Models are immutable.`phpnomad.model.arrayMethod`Models must not have `toArray()` or `fromArray()`. Use a separate adapter class.### Adapters

[](#adapters)

IdentifierDescription`phpnomad.adapter.notImplementing`Classes named `*Adapter` or in `Adapters` namespaces must implement `ModelAdapter`. Exempts `MutationAdapter` implementations.### Events

[](#events)

IdentifierDescription`phpnomad.event.notImplementing`Classes in `Events` namespaces or named `*Event` must implement `PHPNomad\Events\Interfaces\Event`.`phpnomad.event.notFinal`Event classes should be declared `final`.`phpnomad.event.notReadonly`Event properties and promoted constructor parameters should be `readonly`.`phpnomad.listener.notImplementing`Classes in `Listeners` namespaces or named `*Listener` must implement `CanHandle`.### DI / Container

[](#di--container)

IdentifierDescription`phpnomad.di.serviceLocator``InstanceProvider::get()` must not be called inside business classes. Use constructor injection. Calls inside initializers and bootstrappers are allowed.`phpnomad.di.missingTrait`Classes implementing `CanSetContainer` must use the `HasSettableContainer` trait.### Initializers

[](#initializers)

IdentifierDescription`phpnomad.initializer.useInterface`Initializers should use `Has*` interfaces (e.g., `HasListeners`, `HasTaskHandlers`) instead of manually calling registration methods like `EventStrategy::attach()`.### Facades

[](#facades)

IdentifierDescription`phpnomad.facade.notExtending`Classes in `Facades` namespaces or named `*Facade` must extend `PHPNomad\Facade\Abstracts\Facade`.`phpnomad.facade.noAbstractInstance`Concrete Facade subclasses must implement `abstractInstance()`.### Database

[](#database)

IdentifierDescription`phpnomad.database.rawSql`Raw SQL strings (`SELECT ... FROM`, `INSERT INTO`, etc.) must not appear in code. Use PHPNomad datastore patterns.`phpnomad.database.scope``QueryBuilder`, `ClauseBuilder`, and `QueryStrategy` must only be used inside Datastore classes.`phpnomad.database.concreteTableHint`Constructor parameters should type-hint the `Datastore` interface, not concrete `Table` subclasses.### Controllers

[](#controllers)

IdentifierDescription`phpnomad.controller.noStatus`Controller `getResponse()` must explicitly set an HTTP status code via `setStatus()` or `setError()`.### Console

[](#console)

IdentifierDescription`phpnomad.command.notImplementing`Classes in `Commands` namespaces or named `*Command` must implement `PHPNomad\Console\Interfaces\Command`.`phpnomad.command.handleReturnType`Command `handle()` methods must declare an `int` return type.### Tasks

[](#tasks)

IdentifierDescription`phpnomad.task.notImplementing`Classes in `Tasks` namespaces or named `*Task` must implement `PHPNomad\Tasks\Interfaces\Task`.`phpnomad.taskHandler.notImplementing`Task handler classes must implement `PHPNomad\Tasks\Interfaces\CanHandleTask`.`phpnomad.task.directHandle`Task handlers must be dispatched via `TaskStrategy::dispatch()`, not by calling `handle()` directly.### Cache

[](#cache)

IdentifierDescription`phpnomad.cache.directStrategy`Business classes should not inject `CacheStrategy` directly. Use `CacheableService` or a Facade.`phpnomad.cache.uncaughtException``CacheStrategy::get()` throws `CachedItemNotFoundException`. Ensure the call is wrapped in a try/catch.`phpnomad.cache.hardcodedTtl`Do not hardcode TTL values as integer literals. Use a `CachePolicy` or configuration constant.`phpnomad.cache.stringConcatKey`Use the `HasCacheKey` interface for cache key generation instead of string concatenation.### General

[](#general)

IdentifierDescription`phpnomad.general.singletonInBusiness``::instance()` singleton calls must not be used outside of Facade classes. Use dependency injection.`phpnomad.general.globalKeyword`The `global` keyword must not be used. Use dependency injection.Suppressing Rules
-----------------

[](#suppressing-rules)

Use PHPStan's built-in ignore syntax:

```
// @phpstan-ignore phpnomad.model.notFinal
class User implements DataModel
{
    // ...
}
```

Or suppress in `phpstan.neon` via baseline:

```
vendor/bin/phpstan --generate-baseline
```

Requirements
------------

[](#requirements)

- PHP 8.2+
- PHPStan 2.0+

License
-------

[](#license)

MIT

###  Health Score

43

—

FairBetter than 89% of packages

Maintenance89

Actively maintained with recent releases

Popularity20

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity46

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

Unknown

Total

1

Last Release

56d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9e6206223bd6f2a57b8ac80605b1b5c3521faaec18ad3f20f25fb728a9a13784?d=identicon)[tstandiford](/maintainers/tstandiford)

---

Top Contributors

[![alexstandiford](https://avatars.githubusercontent.com/u/8210827?v=4)](https://github.com/alexstandiford "alexstandiford (3 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/phpnomad-phpstan-rules/health.svg)

```
[![Health](https://phpackages.com/badges/phpnomad-phpstan-rules/health.svg)](https://phpackages.com/packages/phpnomad-phpstan-rules)
```

###  Alternatives

[ticketswap/phpstan-error-formatter

A minimalistic error formatter for PHPStan

87670.5k52](/packages/ticketswap-phpstan-error-formatter)[slam/phpstan-extensions

Slam extension of phpstan

712.5M77](/packages/slam-phpstan-extensions)[tomasvotruba/ctor

Prefer constructor over always called setters

1524.9k19](/packages/tomasvotruba-ctor)[ergebnis/rector-rules

Provides rules for rector/rector.

10226.6k48](/packages/ergebnis-rector-rules)[shopsys/coding-standards

Coding standards definition compatible with PSR-2

20276.8k20](/packages/shopsys-coding-standards)[johnbillion/wp-compat

PHPStan extension to help verify that your PHP code is compatible with a given version of WordPress

25152.4k15](/packages/johnbillion-wp-compat)

PHPackages © 2026

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