Completed
Push — master ( d70775...825d10 )
by Kacper
02:48
created

TerminatorToken   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 5
c 4
b 0
f 0
lcom 2
cbo 4
dl 0
loc 30
ccs 17
cts 17
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A validate() 0 7 2
A processStart() 0 4 1
A processEnd() 0 14 2
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\Context;
21
use Kadet\Highlighter\Parser\Result;
22
use Kadet\Highlighter\Parser\TokenIterator;
23
24
/**
25
 * Class TerminatorToken
26
 *
27
 * @package Kadet\Highlighter\Parser\Token
28
 *
29
 * @property array $closes
30
 */
31
class TerminatorToken extends MetaToken
32
{
33 2
    protected function validate(Context $context)
34
    {
35 2
        $this->setValid(
36 2
            $context->language === $this->rule->language &&
37 1
            $this->rule->validator->validate($context)
38 2
        );
39 2
    }
40
41 1
    protected function processStart(Context $context, Language $language, Result $result, TokenIterator $tokens)
42
    {
43 1
        return true; // That type of token makes no sense as start, just omit it.
44
    }
45
46
    protected function processEnd(Context $context, Language $language, Result $result, TokenIterator $tokens)
47
    {
48 1
        foreach(array_filter($context->stack, function ($name) {
49 1
            return in_array($name, $this->closes);
50 1
        }) as $hash => $name) {
51 1
            $end = new Token($name, ['pos' => $this->pos]);
52 1
            $tokens[$hash]->setEnd($end);
53 1
            $result->append($end);
54
55 1
            unset($context->stack[$hash]);
56 1
        }
57
58 1
        return true;
59
    }
60
}
61