Completed
Pull Request — master (#470)
by Claus
01:32
created

Context::__construct()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
nc 4
nop 2
dl 0
loc 12
rs 9.8666
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
namespace TYPO3Fluid\Fluid\Core\Parser;
4
5
/*
6
 * This file belongs to the package "TYPO3 Fluid".
7
 * See LICENSE.txt that was shipped with this package.
8
 */
9
10
/**
11
 * Context collection used by Sequencer when splitting templates.
12
 */
13
class Context
14
{
15
    public const CONTEXT_ROOT = 0;
16
    public const CONTEXT_INLINE = 1;
17
    public const CONTEXT_TAG = 2;
18
    public const CONTEXT_ARRAY= 3;
19
    public const CONTEXT_QUOTED = 4;
20
    public const CONTEXT_ATTRIBUTES = 5;
21
    public const CONTEXT_DEAD = 6;
22
    public const CONTEXT_PROTECTED = 7;
23
    public const CONTEXT_ACCESSOR = 8;
24
    public const CONTEXT_DATA = 9;
25
    public const CONTEXT_TOGGLE = 10;
26
    public const CONTEXT_EMPTY = 11;
27
    public const CONTEXT_BOOLEAN = 12;
28
    public const CONTEXT_INACTIVE = 13;
29
30
    public $context = self::CONTEXT_ROOT;
31
    public $primaryMask = 0;
32
    public $secondaryMask = 0;
33
    public $bytes = [];
34
35
    public function __construct(int $context, string $tokens)
36
    {
37
        $this->context = $context;
38
        foreach (unpack('C*', $tokens) as $byte) {
39
            $this->bytes[] = $byte;
40
            if ($byte >= 64) {
41
                $this->secondaryMask |= (1 << ($byte - Splitter::MAP_SHIFT));
42
            } elseif ($byte < 64) {
43
                $this->primaryMask |= (1 << $byte);
44
            }
45
        }
46
    }
47
}
48