-
Notifications
You must be signed in to change notification settings - Fork 651
/
ContainsLiteralVisitor.php
45 lines (38 loc) · 1.07 KB
/
ContainsLiteralVisitor.php
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
<?php
namespace Psalm\Internal\TypeVisitor;
use Psalm\Type\Atomic\TArray;
use Psalm\Type\Atomic\TFalse;
use Psalm\Type\Atomic\TLiteralFloat;
use Psalm\Type\Atomic\TLiteralInt;
use Psalm\Type\Atomic\TLiteralString;
use Psalm\Type\Atomic\TTrue;
use Psalm\Type\NodeVisitor;
use Psalm\Type\TypeNode;
class ContainsLiteralVisitor extends NodeVisitor
{
/**
* @var bool
*/
private $contains_literal = false;
protected function enterNode(TypeNode $type): ?int
{
if ($type instanceof TLiteralString
|| $type instanceof TLiteralInt
|| $type instanceof TLiteralFloat
|| $type instanceof TTrue
|| $type instanceof TFalse
) {
$this->contains_literal = true;
return NodeVisitor::STOP_TRAVERSAL;
}
if ($type instanceof TArray && $type->isEmptyArray()) {
$this->contains_literal = true;
return NodeVisitor::STOP_TRAVERSAL;
}
return null;
}
public function matches(): bool
{
return $this->contains_literal;
}
}