Skip to content

Commit

Permalink
[DX] Add strict PHPStan rules - step #6 (#1335)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba authored Nov 28, 2021
1 parent 21c4a84 commit f90d7e5
Show file tree
Hide file tree
Showing 11 changed files with 17 additions and 14 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
"nategood/httpful": "^0.3.2",
"phpstan/extension-installer": "^1.1",
"phpstan/phpstan-nette": "^1.0",
"phpstan/phpstan-strict-rules": "^1.1",
"phpstan/phpstan-webmozart-assert": "^1.0",
"phpunit/phpunit": "^9.5",
"rector/phpstan-rules": "^0.4.15",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use PHPStan\Type\Type;

/**
* @template TNode as Node
* @template TNode as \PhpParser\Node
*/
interface NodeTypeResolverInterface
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Rector\NodeTypeResolver\NodeTypeResolver;

use PhpParser\Node;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\Cast;
use PhpParser\Node\Expr\Cast\Array_;
use PhpParser\Node\Expr\Cast\Bool_;
Expand Down Expand Up @@ -40,7 +39,7 @@ final class CastTypeResolver implements NodeTypeResolverInterface
];

/**
* @return array<class-string<Expr>>
* @return array<class-string<Node>>
*/
public function getNodeClasses(): array
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
final class ClassAndInterfaceTypeResolver implements NodeTypeResolverInterface
{
/**
* @return class-string[]
* @return array<class-string<Node>>
*/
public function getNodeClasses(): array
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function autowire(NodeTypeResolver $nodeTypeResolver): void
}

/**
* @return class-string[]
* @return array<class-string<Node>>
*/
public function getNodeClasses(): array
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Rector\NodeTypeResolver\NodeTypeResolver;

use PhpParser\Node;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\New_;
use PhpParser\Node\Name;
use PhpParser\Node\Stmt\Class_;
Expand Down Expand Up @@ -34,7 +33,7 @@ public function __construct(
}

/**
* @return array<class-string<Expr>>
* @return array<class-string<Node>>
*/
public function getNodeClasses(): array
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Rector\NodeTypeResolver\NodeTypeResolver;

use PhpParser\Node;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\PropertyFetch;
use PhpParser\Node\Stmt\ClassLike;
use PHPStan\Analyser\Scope;
Expand Down Expand Up @@ -43,7 +42,7 @@ public function autowire(NodeTypeResolver $nodeTypeResolver): void
}

/**
* @return array<class-string<Expr>>
* @return array<class-string<Node>>
*/
public function getNodeClasses(): array
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Rector\NodeTypeResolver\NodeTypeResolver;

use PhpParser\Node;
use PhpParser\Node\Expr;
use PhpParser\Node\Scalar;
use PhpParser\Node\Scalar\DNumber;
use PhpParser\Node\Scalar\Encapsed;
Expand All @@ -26,7 +25,7 @@
final class ScalarTypeResolver implements NodeTypeResolverInterface
{
/**
* @return array<class-string<Expr>>
* @return array<class-string<Node>>
*/
public function getNodeClasses(): array
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function autowire(NodeTypeResolver $nodeTypeResolver): void
}

/**
* @return class-string[]
* @return array<class-string<Node>>
*/
public function getNodeClasses(): array
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Rector\NodeTypeResolver\NodeTypeResolver;

use PhpParser\Node;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Param;
use PHPStan\Analyser\Scope;
Expand All @@ -30,7 +29,7 @@ public function __construct(
}

/**
* @return array<class-string<Expr>>
* @return array<class-string<Node>>
*/
public function getNodeClasses(): array
{
Expand Down
7 changes: 7 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -590,3 +590,10 @@ parameters:
- '#Method Rector\\PhpAttribute\\Contract\\AnnotationToAttributeMapperInterface\:\:map\(\) return type has no value type specified in iterable type array#'
- '#Method Rector\\PhpAttribute\\AnnotationToAttributeMapper\\(.*?)AnnotationToAttributeMapper\:\:map\(\) return type has no value type specified in iterable type array#'

# confused generics
- '#Return type \(array<class\-string<PhpParser\\Node\>\>\) of method Rector\\NodeTypeResolver\\NodeTypeResolver\\(.*?)TypeResolver\:\:getNodeClasses\(\) should be covariant with return type \(array<class\-string<PhpParser\\Node\\(.*?)\>\>\) of method Rector\\NodeTypeResolver\\Contract\\NodeTypeResolverInterface<PhpParser\\Node\\(.*?)\>\:\:getNodeClasses\(\)#'

# confused from while re-type
-
message: '#Instanceof between PhpParser\\Node\\Expr\\BinaryOp\\BooleanAnd and PhpParser\\Node\\Expr\\BinaryOp will always evaluate to true#'
path: packages/NodeCollector/NodeAnalyzer/BooleanAndAnalyzer.php

0 comments on commit f90d7e5

Please sign in to comment.