Completed
Branch 0.8-dev (c4d6ef)
by Kacper
02:50
created

TerminatorToken::processEnd()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 14
ccs 0
cts 9
cp 0
rs 9.4285
cc 2
eloc 9
nc 2
nop 4
crap 6
1
<?php
2
/**
3
 * Highlighter
4
 *
5
 * Copyright (C) 2016, Some right reserved.
6
 *
7
 * @author Kacper "Kadet" Donat <[email protected]>
8
 *
9
 * Contact with author:
10
 * Xmpp: [email protected]
11
 * E-mail: [email protected]
12
 *
13
 * From Kadet with love.
14
 */
15
16
namespace Kadet\Highlighter\Parser\Token;
17
18
19
use Kadet\Highlighter\Language\Language;
20
use Kadet\Highlighter\Parser\Result;
21
use Kadet\Highlighter\Parser\TokenIterator;
22
23
/**
24
 * Class TerminatorToken
25
 *
26
 * @package Kadet\Highlighter\Parser\Token
27
 *
28
 * @property array $closes
29
 */
30
class TerminatorToken extends Token
31
{
32
    protected function processStart(array &$context, Language $language, Result $result, TokenIterator $tokens)
33
    {
34
        return true; // That type of token makes no sense as start, just omit it.
35
    }
36
37
    protected function processEnd(array &$context, Language $language, Result $result, TokenIterator $tokens)
38
    {
39
        foreach(array_filter($context, function ($name) {
40
            return in_array($name, $this->closes);
41
        }) as $hash => $name) {
42
            $end = new Token([$name, 'pos' => $this->pos]);
43
            $tokens[$hash]->setEnd($end);
44
            $result->append($end);
45
46
            unset($context[$hash]);
47
        }
48
49
        return true;
50
    }
51
52
}