CompoundBegin   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 11
c 2
b 0
f 0
dl 0
loc 48
ccs 12
cts 12
cp 1
rs 10
wmc 7

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setValue() 0 5 1
A endsChunk() 0 3 1
A mutateState() 0 10 5
1
<?php
2
3
namespace Cerbero\JsonParser\Tokens;
4
5
use Cerbero\JsonParser\ValueObjects\State;
6
7
/**
8
 * The token that begins compound data (JSON arrays or objects).
9
 *
10
 */
11
final class CompoundBegin extends Token
12
{
13
    /**
14
     * Whether this compound should be lazy loaded.
15
     *
16
     * @var bool
17
     */
18
    public bool $shouldLazyLoad = false;
19
20
    /**
21
     * Mutate the given state
22
     *
23
     * @param State $state
24
     * @return void
25
     */
26 357
    public function mutateState(State $state): void
27
    {
28 357
        if ($this->shouldLazyLoad = $this->shouldLazyLoad && $state->tree->depth() >= 0) {
0 ignored issues
show
Comprehensibility introduced by
Consider adding parentheses for clarity. Current Interpretation: $this->shouldLazyLoad = ...te->tree->depth() >= 0), Probably Intended Meaning: ($this->shouldLazyLoad =...ate->tree->depth() >= 0
Loading history...
29 34
            $state->expectedToken = $state->tree->inObject() ? Tokens::AFTER_OBJECT_VALUE : Tokens::AFTER_ARRAY_VALUE;
30 34
            return;
31
        }
32
33 357
        $state->expectsKey = $beginsObject = $this->value == '{';
34 357
        $state->expectedToken = $beginsObject ? Tokens::AFTER_OBJECT_BEGIN : Tokens::AFTER_ARRAY_BEGIN;
35 357
        $state->tree->deepen($beginsObject);
36
    }
37
38
    /**
39
     * Set the token value
40
     *
41
     * @param string $value
42
     * @return static
43
     */
44 357
    public function setValue(string $value): static
45
    {
46 357
        $this->shouldLazyLoad = false;
47
48 357
        return parent::setValue($value);
49
    }
50
51
    /**
52
     * Determine whether this token ends a JSON chunk
53
     *
54
     * @return bool
55
     */
56 357
    public function endsChunk(): bool
57
    {
58 357
        return $this->shouldLazyLoad;
59
    }
60
}
61