Repository navigation
Expand file tree
/
Copy pathDeclareHandler.php
More file actions
79 lines (70 loc) · 2.69 KB
/
Copy pathDeclareHandler.php
File metadata and controls
79 lines (70 loc) · 2.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php declare(strict_types = 1);
namespace PHPStan\Analyser\StmtHandler;
use PhpParser\Node\Scalar\Int_;
use PhpParser\Node\Stmt;
use PhpParser\Node\Stmt\Declare_;
use PHPStan\Analyser\ExpressionContext;
use PHPStan\Analyser\ExpressionResultStorage;
use PHPStan\Analyser\InternalStatementResult;
use PHPStan\Analyser\MutatingScope;
use PHPStan\Analyser\NodeScopeResolver;
use PHPStan\Analyser\StatementContext;
use PHPStan\Analyser\StmtHandler;
use PHPStan\Dependency\Dependencies;
use PHPStan\DependencyInjection\AutowiredService;
use PHPStan\Turbo\ShadowedByTurboExtension;
/**
* @implements StmtHandler<Declare_>
*/
#[AutowiredService]
#[ShadowedByTurboExtension(implementation: __DIR__ . '/../../../turbo-ext/src/DeclareHandler.cpp')]
final class DeclareHandler implements StmtHandler
{
public function supports(Stmt $stmt): bool
{
return $stmt instanceof Declare_;
}
public function processStmt(
NodeScopeResolver $nodeScopeResolver,
Stmt $stmt,
MutatingScope $scope,
ExpressionResultStorage $storage,
callable $nodeCallback,
StatementContext $context,
): InternalStatementResult
{
$dependencies = [];
$hasYield = false;
$throwPoints = [];
$impurePoints = [];
$alwaysTerminating = false;
$exitPoints = [];
$variableFlow = null;
foreach ($stmt->declares as $declare) {
$nodeScopeResolver->callNodeCallback($nodeCallback, $declare, $scope, $storage);
// the value is a constant scalar - process it so its result is stored
// before the callback fires on it, like every other expression node
$dependencies[] = $nodeScopeResolver->processExprNode($stmt, $declare->value, $scope, $storage, $nodeCallback, ExpressionContext::createDeep($context->shouldResolveTemplateArguments()))->getDependencies();
if (
$declare->key->name !== 'strict_types'
|| !($declare->value instanceof Int_)
|| $declare->value->value !== 1
) {
continue;
}
$scope = $scope->enterDeclareStrictTypes();
}
if ($stmt->stmts !== null) {
$result = $nodeScopeResolver->processStmtNodesInternal($stmt, $stmt->stmts, $scope, $storage, $nodeCallback, $context);
$dependencies[] = $result->getDependencies();
$scope = $result->getScope();
$hasYield = $result->hasYield();
$throwPoints = $result->getThrowPoints();
$impurePoints = $result->getImpurePoints();
$alwaysTerminating = $result->isAlwaysTerminating();
$exitPoints = $result->getExitPoints();
$variableFlow = $result->getVariableFlow();
}
return new InternalStatementResult($scope, hasYield: $hasYield, isAlwaysTerminating: $alwaysTerminating, exitPoints: $exitPoints, throwPoints: $throwPoints, impurePoints: $impurePoints, variableFlow: $variableFlow, dependencies: Dependencies::merge(...$dependencies));
}
}