Token::isValue()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
namespace Cerbero\JsonParser\Tokens;
4
5
use Cerbero\JsonParser\ValueObjects\State;
6
use Stringable;
7
8
/**
9
 * The abstract implementation of a token.
10
 *
11
 */
12
abstract class Token implements Stringable
13
{
14
    /**
15
     * The token value.
16
     *
17
     * @var string
18
     */
19
    protected string $value;
20
21
    /**
22
     * Mutate the given state
23
     *
24
     * @param State $state
25
     * @return void
26
     */
27
    abstract public function mutateState(State $state): void;
28
29
    /**
30
     * Determine whether this token matches the given type
31
     *
32
     * @param int $type
33
     * @return bool
34
     */
35 357
    public function matches(int $type): bool
36
    {
37 357
        return (Tokens::TYPES[$this->value[0]] & $type) != 0;
38
    }
39
40
    /**
41
     * Set the token value
42
     *
43
     * @param string $value
44
     * @return static
45
     */
46 357
    public function setValue(string $value): static
47
    {
48 357
        $this->value = $value;
49
50 357
        return $this;
51
    }
52
53
    /**
54
     * Determine whether the token is a value
55
     *
56
     * @return bool
57
     */
58 357
    public function isValue(): bool
59
    {
60 357
        return (Tokens::TYPES[$this->value[0]] | Tokens::VALUE_ANY) == Tokens::VALUE_ANY;
61
    }
62
63
    /**
64
     * Determine whether this token ends a JSON chunk
65
     *
66
     * @return bool
67
     */
68 297
    public function endsChunk(): bool
69
    {
70 297
        return false;
71
    }
72
73
    /**
74
     * Retrieve the underlying token value
75
     *
76
     * @return string
77
     */
78 323
    public function __toString(): string
79
    {
80 323
        return $this->value;
81
    }
82
}
83