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