-
Notifications
You must be signed in to change notification settings - Fork 571
Expand file tree
/
Copy pathExpressionResultStorage.php
More file actions
47 lines (37 loc) · 1.12 KB
/
ExpressionResultStorage.php
File metadata and controls
47 lines (37 loc) · 1.12 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
<?php declare(strict_types = 1);
namespace PHPStan\Analyser;
use Fiber;
use PhpParser\Node\Expr;
use PHPStan\Analyser\Fiber\ExpressionAnalysisRequest;
use PHPStan\ShouldNotHappenException;
use SplObjectStorage;
use function get_class;
use function sprintf;
final class ExpressionResultStorage
{
/** @var SplObjectStorage<Expr, ExpressionResult> */
private SplObjectStorage $results;
/** @var array<array{fiber: Fiber<mixed, ExpressionResult, null, ExpressionAnalysisRequest>, request: ExpressionAnalysisRequest}> */
public array $pendingFibers = [];
public function __construct()
{
$this->results = new SplObjectStorage();
}
public function duplicate(): self
{
$new = new self();
$new->results->addAll($this->results);
return $new;
}
public function storeResult(Expr $expr, ExpressionResult $result): void
{
if (isset($this->results[$expr])) {
throw new ShouldNotHappenException(sprintf('already stored %s on line %d', get_class($expr), $expr->getStartLine()));
}
$this->results[$expr] = $result;
}
public function findResult(Expr $expr): ?ExpressionResult
{
return $this->results[$expr] ?? null;
}
}