Skip to content

Commit 5fa2f28

Browse files
committed
resolveType in closures handlers
1 parent 2681a90 commit 5fa2f28

File tree

8 files changed

+487
-422
lines changed

8 files changed

+487
-422
lines changed

src/Analyser/DirectInternalScopeFactory.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ public function __construct(
3434
private TypeSpecifier $typeSpecifier,
3535
private PropertyReflectionFinder $propertyReflectionFinder,
3636
private Parser $parser,
37-
private NodeScopeResolver $nodeScopeResolver,
3837
private PhpVersion $phpVersion,
3938
private AttributeReflectionFactory $attributeReflectionFactory,
4039
private int|array|null $configPhpVersion,
@@ -80,7 +79,6 @@ public function create(
8079
$this->typeSpecifier,
8180
$this->propertyReflectionFinder,
8281
$this->parser,
83-
$this->nodeScopeResolver,
8482
$this->constantResolver,
8583
$context,
8684
$this->phpVersion,
@@ -117,7 +115,6 @@ public function toFiberFactory(): InternalScopeFactory
117115
$this->typeSpecifier,
118116
$this->propertyReflectionFinder,
119117
$this->parser,
120-
$this->nodeScopeResolver,
121118
$this->phpVersion,
122119
$this->attributeReflectionFactory,
123120
$this->configPhpVersion,
@@ -139,7 +136,6 @@ public function toMutatingFactory(): InternalScopeFactory
139136
$this->typeSpecifier,
140137
$this->propertyReflectionFinder,
141138
$this->parser,
142-
$this->nodeScopeResolver,
143139
$this->phpVersion,
144140
$this->attributeReflectionFactory,
145141
$this->configPhpVersion,

src/Analyser/DirectInternalScopeFactoryFactory.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ public function __construct(
3030
private TypeSpecifier $typeSpecifier,
3131
private PropertyReflectionFinder $propertyReflectionFinder,
3232
private Parser $parser,
33-
private NodeScopeResolver $nodeScopeResolver,
3433
private PhpVersion $phpVersion,
3534
private AttributeReflectionFactory $attributeReflectionFactory,
3635
private int|array|null $configPhpVersion,
@@ -54,7 +53,6 @@ public function create(?callable $nodeCallback): DirectInternalScopeFactory
5453
$this->typeSpecifier,
5554
$this->propertyReflectionFinder,
5655
$this->parser,
57-
$this->nodeScopeResolver,
5856
$this->phpVersion,
5957
$this->attributeReflectionFactory,
6058
$this->configPhpVersion,

src/Analyser/ExprHandler/ArrowFunctionHandler.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@
99
use PHPStan\Analyser\ExpressionResult;
1010
use PHPStan\Analyser\ExpressionResultStorage;
1111
use PHPStan\Analyser\ExprHandler;
12+
use PHPStan\Analyser\ExprHandler\Helper\ClosureTypeResolver;
1213
use PHPStan\Analyser\MutatingScope;
1314
use PHPStan\Analyser\NodeScopeResolver;
1415
use PHPStan\DependencyInjection\AutowiredService;
16+
use PHPStan\Type\Type;
1517

1618
/**
1719
* @implements ExprHandler<ArrowFunction>
@@ -20,6 +22,12 @@
2022
final class ArrowFunctionHandler implements ExprHandler
2123
{
2224

25+
public function __construct(
26+
private ClosureTypeResolver $closureTypeResolver,
27+
)
28+
{
29+
}
30+
2331
public function supports(Expr $expr): bool
2432
{
2533
return $expr instanceof ArrowFunction;
@@ -38,4 +46,12 @@ public function processExpr(NodeScopeResolver $nodeScopeResolver, Stmt $stmt, Ex
3846
);
3947
}
4048

49+
/**
50+
* @param ArrowFunction $expr
51+
*/
52+
public function resolveType(MutatingScope $scope, Expr $expr): Type
53+
{
54+
return $this->closureTypeResolver->getClosureType($scope, $expr);
55+
}
56+
4157
}

src/Analyser/ExprHandler/ClosureHandler.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@
99
use PHPStan\Analyser\ExpressionResult;
1010
use PHPStan\Analyser\ExpressionResultStorage;
1111
use PHPStan\Analyser\ExprHandler;
12+
use PHPStan\Analyser\ExprHandler\Helper\ClosureTypeResolver;
1213
use PHPStan\Analyser\MutatingScope;
1314
use PHPStan\Analyser\NodeScopeResolver;
1415
use PHPStan\DependencyInjection\AutowiredService;
16+
use PHPStan\Type\Type;
1517

1618
/**
1719
* @implements ExprHandler<Closure>
@@ -20,6 +22,12 @@
2022
final class ClosureHandler implements ExprHandler
2123
{
2224

25+
public function __construct(
26+
private ClosureTypeResolver $closureTypeResolver,
27+
)
28+
{
29+
}
30+
2331
public function supports(Expr $expr): bool
2432
{
2533
return $expr instanceof Closure;
@@ -39,4 +47,12 @@ public function processExpr(NodeScopeResolver $nodeScopeResolver, Stmt $stmt, Ex
3947
);
4048
}
4149

50+
/**
51+
* @param Closure $expr
52+
*/
53+
public function resolveType(MutatingScope $scope, Expr $expr): Type
54+
{
55+
return $this->closureTypeResolver->getClosureType($scope, $expr);
56+
}
57+
4258
}

0 commit comments

Comments
 (0)