Skip to content

Commit 100073b

Browse files
committed
added readme.md
1 parent c4517d5 commit 100073b

File tree

1 file changed

+81
-0
lines changed

1 file changed

+81
-0
lines changed

readme.md

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# PHPStan extensions for Nette libraries
2+
3+
![Nette PHPStan Rules](https://github.com/user-attachments/assets/c231ed47-a413-4dd2-81ef-83e52c080427)
4+
5+
[![Downloads this Month](https://img.shields.io/packagist/dm/nette/phpstan-rules.svg)](https://packagist.org/packages/nette/phpstan-rules)
6+
[![Tests](https://github.com/nette/phpstan-rules/workflows/Tests/badge.svg?branch=master)](https://github.com/nette/phpstan-rules/actions)
7+
[![Latest Stable Version](https://poser.pugx.org/nette/phpstan-rules/v/stable)](https://github.com/nette/phpstan-rules/releases)
8+
[![License](https://img.shields.io/badge/license-New%20BSD-blue.svg)](https://github.com/nette/phpstan-rules/blob/master/license.md)
9+
10+
 <!---->
11+
12+
<h3>
13+
14+
Makes [PHPStan](https://phpstan.org) smarter about Nette code. Install, and it just works — more precise types, fewer false positives.
15+
16+
</h3>
17+
18+
 <!---->
19+
20+
21+
## Installation
22+
23+
Install via Composer:
24+
25+
```shell
26+
composer require --dev nette/phpstan-rules
27+
```
28+
29+
Requirements: PHP 8.1 or higher and PHPStan 2.1+.
30+
31+
If you use [phpstan/extension-installer](https://github.com/phpstan/extension-installer), the extension is registered automatically. Otherwise add to your `phpstan.neon`:
32+
33+
```neon
34+
includes:
35+
- vendor/nette/phpstan-rules/extension.neon
36+
```
37+
38+
 <!---->
39+
40+
## What's Included
41+
42+
<!---->
43+
44+
**Precise return types** — narrows return types of `Strings::match()`, `matchAll()`, `split()`, `Helpers::falseToNull()`, and `Expect::array()` based on the arguments you pass.
45+
46+
**Removes `|false` from PHP functions** — functions like `getcwd`, `json_encode`, `preg_split`, and [many more](extension-php.neon) return `string|false` even though `false` is unrealistic on modern systems.
47+
48+
**Assert type narrowing** — PHPStan understands type guarantees after `Tester\Assert` calls like `notNull()`, `type()`, `true()`, etc.
49+
50+
**False positive suppression** — silences known PHPStan false positives in Nette patterns (arrow functions passed as `void` callbacks, runtime type validation closures).
51+
52+
<!---->
53+
54+
### Type Assertion Testing Helper
55+
56+
For Nette package developers: `TypeAssert` lets you verify type inference in tests using [Nette Tester](https://tester.nette.org):
57+
58+
```php
59+
use Nette\PHPStan\Tester\TypeAssert;
60+
61+
TypeAssert::assertTypes(__DIR__ . '/data/types.php', [__DIR__ . '/../extension.neon']);
62+
```
63+
64+
The data file uses `assertType()` from PHPStan:
65+
66+
```php
67+
use function PHPStan\Testing\assertType;
68+
69+
assertType('non-empty-string', getcwd());
70+
assertType('string', Normalizer::normalize('foo'));
71+
```
72+
73+
 <!---->
74+
75+
## [Support Me](https://github.com/sponsors/dg)
76+
77+
Do you like Nette? Are you looking forward to the new features?
78+
79+
[![Buy me a coffee](https://files.nette.org/icons/donation-3.svg)](https://github.com/sponsors/dg)
80+
81+
Thank you!

0 commit comments

Comments
 (0)