Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 2 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ function example(MyClass $class) {

### forbidUselessNullableReturn
- Denies marking closure/function/method return type as nullable when null is never returned
- Recommended to be used together with `uselessPrivatePropertyDefaultValue` and `UselessPrivatePropertyNullabilityRule`
- Recommended to be used together with `uselessPrivatePropertyDefaultValue`
```php
public function example(int $foo): ?int { // null never returned
if ($foo < 0) {
Expand Down Expand Up @@ -664,7 +664,7 @@ try {
- Detects useless default value of a private property that is always initialized in constructor.
- Cannot handle conditions or private method calls within constructor.
- When enabled, return statements in constructors are denied to avoid false positives
- Recommended to be used with `uselessPrivatePropertyNullability` and `forbidUselessNullableReturn`
- Recommended to be used with `forbidUselessNullableReturn`
```php
class Example
{
Expand All @@ -677,29 +677,6 @@ class Example
}
```

### uselessPrivatePropertyNullability:
- Detects useless nullability of a private property by checking type of all assignments.
- Works only with natively typehinted properties
- Recommended to be used with `uselessPrivatePropertyNullability` and `forbidUselessNullableReturn` as removing useless default value may cause useless nullability to be detected
- PHPStan 1.12 with bleeding edge contains more generic version of this rule under `property.unusedType` error identifier

```php
class Example
{
private ?int $field; // useless nullability

public function __construct()
{
$this->field = 1;
}

public function setField(int $value)
{
$this->field = $value;
}
}
```

## Native PHPStan extra strictness
Some strict behaviour in PHPStan is not enabled by default, consider enabling extra strictness even there:

Expand Down
13 changes: 0 additions & 13 deletions rules.neon
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,6 @@ parameters:
reportEvenIfExceptionIsNotAcceptableByRethrownOne: true
uselessPrivatePropertyDefaultValue:
enabled: %shipmonkRules.enableAllRules%
uselessPrivatePropertyNullability:
enabled: %shipmonkRules.enableAllRules%

parametersSchema:
shipmonkRules: structure([
Expand Down Expand Up @@ -212,9 +210,6 @@ parametersSchema:
uselessPrivatePropertyDefaultValue: structure([
enabled: bool()
])
uselessPrivatePropertyNullability: structure([
enabled: bool()
])
])

conditionalTags:
Expand Down Expand Up @@ -290,17 +285,13 @@ conditionalTags:
phpstan.rules.rule: %shipmonkRules.requirePreviousExceptionPass.enabled%
ShipMonk\PHPStan\Rule\UselessPrivatePropertyDefaultValueRule:
phpstan.rules.rule: %shipmonkRules.uselessPrivatePropertyDefaultValue.enabled%
ShipMonk\PHPStan\Rule\UselessPrivatePropertyNullabilityRule:
phpstan.rules.rule: %shipmonkRules.uselessPrivatePropertyNullability.enabled%

ShipMonk\PHPStan\Visitor\UnusedExceptionVisitor:
phpstan.parser.richParserNodeVisitor: %shipmonkRules.forbidUnusedException.enabled%
ShipMonk\PHPStan\Visitor\UnusedMatchVisitor:
phpstan.parser.richParserNodeVisitor: %shipmonkRules.forbidUnusedMatchResult.enabled%
ShipMonk\PHPStan\Visitor\TopLevelConstructorPropertyFetchMarkingVisitor:
phpstan.parser.richParserNodeVisitor: %shipmonkRules.uselessPrivatePropertyDefaultValue.enabled%
ShipMonk\PHPStan\Visitor\ClassPropertyAssignmentVisitor:
phpstan.parser.richParserNodeVisitor: %shipmonkRules.uselessPrivatePropertyNullability.enabled%

services:
-
Expand Down Expand Up @@ -405,8 +396,6 @@ services:
class: ShipMonk\PHPStan\Rule\ForbidReturnInConstructorRule
-
class: ShipMonk\PHPStan\Rule\UselessPrivatePropertyDefaultValueRule
-
class: ShipMonk\PHPStan\Rule\UselessPrivatePropertyNullabilityRule

-
class: ShipMonk\PHPStan\Rule\RequirePreviousExceptionPassRule
Expand All @@ -418,5 +407,3 @@ services:
class: ShipMonk\PHPStan\Visitor\UnusedMatchVisitor
-
class: ShipMonk\PHPStan\Visitor\TopLevelConstructorPropertyFetchMarkingVisitor
-
class: ShipMonk\PHPStan\Visitor\ClassPropertyAssignmentVisitor
119 changes: 0 additions & 119 deletions src/Rule/UselessPrivatePropertyNullabilityRule.php

This file was deleted.

66 changes: 0 additions & 66 deletions src/Visitor/ClassPropertyAssignmentVisitor.php

This file was deleted.

36 changes: 0 additions & 36 deletions tests/Rule/UselessPrivatePropertyNullabilityRuleTest.php

This file was deleted.

This file was deleted.

52 changes: 0 additions & 52 deletions tests/Rule/data/UselessPrivatePropertyNullabilityRule/code.php

This file was deleted.

Loading