Passed
Branch 0.8-dev (82421f)
by Kacper
02:45
created

Context::has()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
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;
17
18
19
use Kadet\Highlighter\Language\Language;
20
use Kadet\Highlighter\Parser\Token\Token;
21
22
class Context
23
{
24
    public $stack = [];
25
    public $language;
26
27 30
    public function __construct(Language $language = null) {
28 30
        $this->language = $language;
29 30
    }
30
31 2
    public function find($needle) {
32 2
        foreach (array_reverse($this->stack, true) as $id => $name) {
33 2
            if($name === $needle) {
34 2
                return $id;
35
            }
36 1
        }
37
38 1
        return false;
39
    }
40
41 14
    public function push(Token $token)
42
    {
43 14
        $this->stack[$token->id] = $token->name;
44 14
    }
45
46 9
    public function pop(Token $token)
47
    {
48 9
        unset($this->stack[$token->id]);
49 9
    }
50
51 2
    public function has($name) {
52 2
        return in_array($name, $this->stack, true);
53
    }
54
55 14
    public static function fromArray(array $array, Language $language = null) {
56 14
        $context = new Context($language);
57 14
        $context->stack = $array;
58 14
        return $context;
59
    }
60
}
61