ScalarString::endsChunk()   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
7
/**
8
 * The scalar string token.
9
 *
10
 */
11
final class ScalarString extends Token
12
{
13
    /**
14
     * Whether this token is an object key.
15
     *
16
     * @var bool
17
     */
18
    private bool $isKey = false;
19
20
    /**
21
     * Mutate the given state
22
     *
23
     * @param State $state
24
     * @return void
25
     */
26 294
    public function mutateState(State $state): void
27
    {
28 294
        if ($this->isKey = $state->expectsKey) {
29 199
            $state->expectsKey = false;
30 199
            $state->expectedToken = Tokens::COLON;
31 199
            return;
32
        }
33
34 291
        $state->expectedToken = $state->tree->inObject() ? Tokens::AFTER_OBJECT_VALUE : Tokens::AFTER_ARRAY_VALUE;
35
    }
36
37
    /**
38
     * Determine whether this token ends a JSON chunk
39
     *
40
     * @return bool
41
     */
42 294
    public function endsChunk(): bool
43
    {
44 294
        return !$this->isKey;
45
    }
46
}
47