Skip to content

Commit

Permalink
misc
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Jun 2, 2024
1 parent 77b619e commit dafc720
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 26 deletions.
20 changes: 16 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

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.

<br>

## Install
Expand All @@ -16,16 +20,24 @@ composer require rector/type-perfect --dev

<br>

@todo enable by configuration


## Configure

Next rules you can enable by configuration:

```yaml
parameters:
type_coverage:
narrow: false
no_mixed: false
null_over_false: false
narrow_param: true
no_mixed: true
null_over_false: true
```
## Narrow Param Types
```php

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

<br>
Expand Down
43 changes: 23 additions & 20 deletions config/extension.neon
Original file line number Diff line number Diff line change
@@ -1,18 +1,38 @@
parametersSchema:
# see https://doc.nette.org/en/schema for configuration
type_perfect: structure([
narrow: bool()
narrow_param: bool()
no_mixed: bool()
null_over_false: bool()
])

# default parameters
# defaults
parameters:
type_perfect:
narrow: false
narrow_param: false
no_mixed: false
null_over_false: false

rules:
# enabled by default
- Rector\TypePerfect\Rules\NoParamTypeRemovalRule
- Rector\TypePerfect\Rules\NoArrayAccessOnObjectRule
- Rector\TypePerfect\Rules\NoIssetOnObjectRule

# turn on by the group name

# narrow_param
- Rector\TypePerfect\Rules\NarrowPublicClassMethodParamTypeRule
- Rector\TypePerfect\Rules\NarrowPrivateClassMethodParamTypeRule
- Rector\TypePerfect\Rules\NarrowReturnObjectTypeRule

# no_mixed
- Rector\TypePerfect\Rules\NoMixedPropertyFetcherRule
- Rector\TypePerfect\Rules\NoMixedMethodCallerRule

# null_over_false
- Rector\TypePerfect\Rules\ReturnNullOverFalseRule

services:
-
factory: Rector\TypePerfect\Configuration
Expand Down Expand Up @@ -44,20 +64,3 @@ services:
class: Rector\TypePerfect\Collector\MethodCallableNode\MethodCallableCollector
tags:
- phpstan.collector

# these rule focus on the whole-project analysis, see https://phpstan.org/developing-extensions/collectors
rules:
# narrow types
- Rector\TypePerfect\Rules\NarrowPublicClassMethodParamTypeRule
- Rector\TypePerfect\Rules\NarrowPrivateClassMethodParamTypeRule
- Rector\TypePerfect\Rules\NarrowReturnObjectTypeRule
- Rector\TypePerfect\Rules\ReturnNullOverFalseRule

# no mixed
- Rector\TypePerfect\Rules\NoMixedPropertyFetcherRule
- Rector\TypePerfect\Rules\NoMixedMethodCallerRule

# simple - always enable these
- Rector\TypePerfect\Rules\NoParamTypeRemovalRule
- Rector\TypePerfect\Rules\NoArrayAccessOnObjectRule
- Rector\TypePerfect\Rules\NoIssetOnObjectRule
4 changes: 2 additions & 2 deletions src/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ public function __construct(
) {
// enabed by default in tests
if (defined('PHPUNIT_COMPOSER_INSTALL')) {
$this->parameters['narrow'] = true;
$this->parameters['narrow_param'] = true;
$this->parameters['no_mixed'] = true;
$this->parameters['null_over_false'] = true;
}
}

public function isNarrowEnabled(): bool
{
return $this->parameters['narrow'] ?? false;
return $this->parameters['narrow_param'] ?? false;
}

public function isNoMixedEnabled(): bool
Expand Down

0 comments on commit dafc720

Please sign in to comment.