1: <?php declare(strict_types = 1);
2:
3: namespace PHPStan\Node;
4:
5: use Override;
6: use PhpParser\Node;
7: use PhpParser\Node\Expr\Closure;
8: use PhpParser\Node\Expr\Yield_;
9: use PhpParser\Node\Expr\YieldFrom;
10: use PhpParser\NodeAbstract;
11: use PHPStan\Analyser\ImpurePoint;
12: use PHPStan\Analyser\StatementResult;
13: use function count;
14:
15: /**
16: * @api
17: */
18: final class ClosureReturnStatementsNode extends NodeAbstract implements ReturnStatementsNode
19: {
20:
21: private Node\Expr\Closure $closureExpr;
22:
23: /**
24: * @param list<ReturnStatement> $returnStatements
25: * @param list<Yield_|YieldFrom> $yieldStatements
26: * @param list<ExecutionEndNode> $executionEnds
27: * @param ImpurePoint[] $impurePoints
28: */
29: public function __construct(
30: Closure $closureExpr,
31: private array $returnStatements,
32: private array $yieldStatements,
33: private StatementResult $statementResult,
34: private array $executionEnds,
35: private array $impurePoints,
36: )
37: {
38: parent::__construct($closureExpr->getAttributes());
39: $this->closureExpr = $closureExpr;
40: }
41:
42: public function getClosureExpr(): Closure
43: {
44: return $this->closureExpr;
45: }
46:
47: public function hasNativeReturnTypehint(): bool
48: {
49: return $this->closureExpr->returnType !== null;
50: }
51:
52: public function getReturnStatements(): array
53: {
54: return $this->returnStatements;
55: }
56:
57: public function getExecutionEnds(): array
58: {
59: return $this->executionEnds;
60: }
61:
62: public function getImpurePoints(): array
63: {
64: return $this->impurePoints;
65: }
66:
67: public function getYieldStatements(): array
68: {
69: return $this->yieldStatements;
70: }
71:
72: public function isGenerator(): bool
73: {
74: return count($this->yieldStatements) > 0;
75: }
76:
77: public function getStatementResult(): StatementResult
78: {
79: return $this->statementResult;
80: }
81:
82: public function returnsByRef(): bool
83: {
84: return $this->closureExpr->byRef;
85: }
86:
87: #[Override]
88: public function getType(): string
89: {
90: return 'PHPStan_Node_ClosureReturnStatementsNode';
91: }
92:
93: /**
94: * @return string[]
95: */
96: #[Override]
97: public function getSubNodeNames(): array
98: {
99: return [];
100: }
101:
102: }
103: