Skip to content

Commit

Permalink
improve README
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Jun 2, 2024
1 parent 0ba5d72 commit 5753681
Showing 1 changed file with 75 additions and 2 deletions.
77 changes: 75 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ Next level type declaration check PHPStan rules.

We use these sets to improve code quality of our clients' code beyond PHPStan features.

These rules make skipped object types explicit, param types narrow and help you to fill more accurate object type hints. If you care about code quality and type safety, add these rules to your CI.
* These rules make skipped object types explicit, param types narrow and help you to fill more accurate object type hints.
* They're easy to enable, even if your code does not pass level 0
* They're effortless to resolve.

If you care about code quality and type safety, add these rules to your CI.

<br>

Expand All @@ -20,7 +24,59 @@ composer require rector/type-perfect --dev

<br>

There are 2 checks enabled out of the box. First one makes sure we don't miss a chance to use `instanceof` to make further code know about exact object type:

```php
private ?SomeType $someType = null;

if (! empty($this->someType)) {
// ...
}

if (! isset($this->someType)) {
// ...
}

// here we only know, that $this->someType is not empty/null
```

:no_good:



```php
if (! $this->someType instanceof SomeType) {
return;
}

// here we know $this->someType is exactly SomeType
```

:heavy_check_mark:

<br>

Second rule checks we use explicit object methods over magic array access:

```php
$article = new Article();

$id = $article['id'];
// we have no idea, what the type is
```
:no_good:


```php
$id = $article->getId();
// we know the type is int
```

:heavy_check_mark:

<br>

## Configure

Expand All @@ -34,10 +90,27 @@ parameters:
null_over_false: true
```
## Narrow Param Types
## 1. Narrow Param Types
```php

```

## 2. No mixed Caller

```php

```

## 3. Null over False

```php

```




Add sets one by one, fix what you find useful and ignore the rest.

<br>
Expand Down

0 comments on commit 5753681

Please sign in to comment.