Test Failed
Push — master ( c19a70...4a5f5f )
by Sebastian
05:20
created

isExplanationFunction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AppLocalize;
6
7
class Localization_Parser_Token_PHP extends Localization_Parser_Token
8
{
9
    private static $explanationFunctions = array(
10
        'tex' => true,
11
        'ptex' => true,
12
        'ptexs' => true
13
    );
14
15
    protected function parseDefinition() : void
16
    {
17
        // some entries are strings, like parentheses, semicolons and the like.
18
        if(is_string($this->definition))
19
        {
20
            $this->token = $this->definition;
21
            $this->value = null;
22
            
23
            if(isset($this->parentToken)) {
24
                $this->line = $this->parentToken->getLine();
25
            }
26
        }
27
        else
28
        {
29
            $this->token = token_name($this->definition[0]);
30
            $this->value = $this->definition[1];
31
            $this->line = $this->definition[2];
32
        }
33
    }
34
35
    /**
36
     * @return string[]
37
     */
38
    public function getFunctionNames() : array
39
    {
40
        return array(
41
            't',
42
            'pt',
43
            'pts',
44
            'tex',
45
            'ptex',
46
            'ptexs'
47
        );
48
    }
49
    
50
    public function isOpeningFuncParams() : bool
51
    {
52
        return $this->getToken() === '(';
53
    }
54
    
55
    public function isClosingFuncParams() : bool
56
    {
57
        return $this->getToken() === ')';
58
    }
59
    
60
    public function isString() : bool
61
    {
62
        return $this->token === 'T_STRING';
63
    }
64
    
65
    public function isEncapsedString() : bool
66
    {
67
        return $this->token === 'T_CONSTANT_ENCAPSED_STRING';
68
    }
69
    
70
    public function isTranslationFunction() : bool
71
    {
72
        return $this->isString() && isset($this->nameLookup[$this->getValue()]);
73
    }
74
    
75
    public function isVariableOrFunction() : bool
76
    {
77
        return $this->token === 'T_VARIABLE' || $this->token === 'T_FUNCTION';
78
    }
79
80
    public function isExplanationFunction() : bool
81
    {
82
        return isset(self::$explanationFunctions[$this->getValue()]);
83
    }
84
    
85
    public function isArgumentSeparator() : bool
86
    {
87
        return $this->getToken() === ',';
88
    }
89
}
90