PHPackages                             nette/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. nette/phpstan-rules

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

nette/phpstan-rules
===================

🐘 PHPStan rules and type extensions for Nette libraries

63.5k↑14.2%20PHPCI passing

Since Mar 10Pushed 2mo ago2 watchersCompare

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

READMEChangelogDependenciesVersions (1)Used By (20)

PHPStan extensions for Nette libraries
======================================

[](#phpstan-extensions-for-nette-libraries)

[![Nette PHPStan Rules](https://private-user-images.githubusercontent.com/194960/547967352-c231ed47-a413-4dd2-81ef-83e52c080427.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NzQzNTYwMTksIm5iZiI6MTc3NDM1NTcxOSwicGF0aCI6Ii8xOTQ5NjAvNTQ3OTY3MzUyLWMyMzFlZDQ3LWE0MTMtNGRkMi04MWVmLTgzZTUyYzA4MDQyNy5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjYwMzI0JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI2MDMyNFQxMjM1MTlaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT1jMWY2N2QwNGIxZmI5ZTU3MjZhYzM4ZTNhYmRmMjExN2I3ZmNmYmFlMmQ0OTBkMDViM2YyZjY5Zjk3MmU1MGFmJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCJ9.Kz_t32OyukeEsNoiDHeh1Hkwy2KQc_iin2yjnCXf0Cw)](https://private-user-images.githubusercontent.com/194960/547967352-c231ed47-a413-4dd2-81ef-83e52c080427.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NzQzNTYwMTksIm5iZiI6MTc3NDM1NTcxOSwicGF0aCI6Ii8xOTQ5NjAvNTQ3OTY3MzUyLWMyMzFlZDQ3LWE0MTMtNGRkMi04MWVmLTgzZTUyYzA4MDQyNy5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjYwMzI0JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI2MDMyNFQxMjM1MTlaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT1jMWY2N2QwNGIxZmI5ZTU3MjZhYzM4ZTNhYmRmMjExN2I3ZmNmYmFlMmQ0OTBkMDViM2YyZjY5Zjk3MmU1MGFmJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCJ9.Kz_t32OyukeEsNoiDHeh1Hkwy2KQc_iin2yjnCXf0Cw)

[![Downloads this Month](https://camo.githubusercontent.com/e6905cb45ef90f24b5263b74d980decc6af80f0c9be6b92a0a1de331bc4294b7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f6e657474652f7068707374616e2d72756c65732e737667)](https://packagist.org/packages/nette/phpstan-rules)[![Tests](https://github.com/nette/phpstan-rules/workflows/Tests/badge.svg?branch=master)](https://github.com/nette/phpstan-rules/actions)[![Latest Stable Version](https://camo.githubusercontent.com/47c9d45d0de7b623892e063d4babe5dbbe27aa8be6653f258e512f1dfdb6a794/68747470733a2f2f706f7365722e707567782e6f72672f6e657474652f7068707374616e2d72756c65732f762f737461626c65)](https://github.com/nette/phpstan-rules/releases)[![License](https://camo.githubusercontent.com/fa7d5fcf2c84b580327af52da95dd751703af65f079dc3c5a0081beac0789718/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4e65772532304253442d626c75652e737667)](https://github.com/nette/phpstan-rules/blob/master/license.md)

Makes [PHPStan](https://phpstan.org) smarter about Nette code. Install, and it just works — more precise types, fewer false positives.

[](#makes-phpstan-smarter-about-nette-code-install-and-it-just-works--more-precise-types-fewer-false-positives)

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

[](#installation)

Install via Composer:

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

Requirements: PHP 8.1 or higher and PHPStan 2.1+.

If you use [phpstan/extension-installer](https://github.com/phpstan/extension-installer), the extension is registered automatically. Otherwise add to your `phpstan.neon`:

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

What's Included
---------------

[](#whats-included)

**Precise return types** — narrows return types of `Strings::match()`, `matchAll()`, `split()`, `Helpers::falseToNull()`, `Expect::array()`, `Arrays::invoke()`, and `Arrays::invokeMethod()` based on the arguments you pass. Also narrows `Container::getComponent()` and `$container['...']` to match the corresponding `createComponent*()` factory return type. For forms, `$form['name']` returns the specific control type (e.g. `TextInput`, `SelectBox`) based on the `addText()`, `addSelect()`, etc. call in the same function.

**Database row mapping** — narrows return types of `Explorer::table()`, `ActiveRow::related()`, and `ActiveRow::ref()` based on a configurable table-to-entity-class convention. For example, `$explorer->table('booking')` returns `Selection` instead of `Selection`. Configure via:

```
parameters:
    nette:
        database:
            mapping:
                convention: App\Entity\*Row   # * = PascalCase table name
                tables:                       # optional explicit overrides
                    special_table: App\Entity\SpecialRow
```

**Asset type narrowing** — narrows return types of `Registry::getMapper()` to the specific mapper class, and `Registry::getAsset()` / `tryGetAsset()` to the specific asset type (e.g. `ImageAsset`, `ScriptAsset`) based on file extension. Also narrows `FilesystemMapper::getAsset()` and `ViteMapper::getAsset()` directly. Configure via:

```
parameters:
    nette:
        assets:
            mapping:
                default: file                   # FilesystemMapper
                images: file                    # FilesystemMapper
                vite: vite                      # ViteMapper
                custom: App\MyMapper            # custom class (FQCN)
```

**Html magic methods** — resolves `$html->getXxx()`, `setXxx()`, and `addXxx()` calls on `Nette\Utils\Html` that go through `__call()` but aren't declared via `@method` annotations.

**Removes `|false` and `|null` from PHP functions** — many native functions like `getcwd`, `json_encode`, `preg_split`, `preg_replace`, and [many more](extension-php.neon) include `false` or `null` in their return type even though these error values are unrealistic on modern systems.

**Assert type narrowing** — PHPStan understands type guarantees after `Tester\Assert` calls like `notNull()`, `type()`, `true()`, etc.

**False positive suppression** — silences known PHPStan false positives in Nette patterns (arrow functions passed as `void` callbacks, runtime type validation closures).

### Type Assertion Testing Helper

[](#type-assertion-testing-helper)

For Nette package developers: `TypeAssert` lets you verify type inference in tests using [Nette Tester](https://tester.nette.org):

```
use Nette\PHPStan\Tester\TypeAssert;

TypeAssert::assertTypes(__DIR__ . '/data/types.php');
TypeAssert::assertNoErrors(__DIR__ . '/data/clean.php');
```

The data file uses `assertType()` from PHPStan:

```
use function PHPStan\Testing\assertType;

assertType('non-empty-string', getcwd());
assertType('string', Normalizer::normalize('foo'));
```

[Support Me](https://github.com/sponsors/dg)
--------------------------------------------

[](#support-me)

Do you like Nette? Are you looking forward to the new features?

[![Buy me a coffee](https://camo.githubusercontent.com/afa7c20ccaac10ac4f1f51669bafb212856b932e0c8b276cb290336cf08624b8/68747470733a2f2f66696c65732e6e657474652e6f72672f69636f6e732f646f6e6174696f6e2d332e737667)](https://github.com/sponsors/dg)

Thank you!

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance57

Moderate activity, may be stable

Popularity29

Limited adoption so far

Community18

Small or concentrated contributor base

Maturity11

Early-stage or recently created project

 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/17f266513a3ca97500ec3d85d562b9279c7a6346358fe2b8d90390ece717a027?d=identicon)[david@grudl.com](/maintainers/david@grudl.com)

---

Top Contributors

[![dg](https://avatars.githubusercontent.com/u/194960?v=4)](https://github.com/dg "dg (24 commits)")

---

Tags

nettephpstan-extension

### Embed Badge

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

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

###  Alternatives

[phpwhois/phpwhois

phpWhois - library for querying whois services and parsing results. Based on phpwhois.org

322392.6k1](/packages/phpwhois-phpwhois)[cakedc/tiny-mce

TinyMCE Plugin for CakePHP

10790.2k](/packages/cakedc-tiny-mce)[imanghafoori/laravel-anypass

A minimal yet powerful package to help you in development.

21421.6k](/packages/imanghafoori-laravel-anypass)[rasteiner/k3-whenquery

Conditionally show fields and sections. Better.

6717.8k](/packages/rasteiner-k3-whenquery)[dragon-code/size-sorter

Easily sort clothing size, height, bra size, furniture size and more

3915.4k](/packages/dragon-code-size-sorter)[geeklabs/ci4-breadcrumbs

Breadcrumb navigation for CodeIgniter 4

2813.5k](/packages/geeklabs-ci4-breadcrumbs)

PHPackages © 2026

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