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

Localization_Parser_Token_PHP   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 81
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 29
c 3
b 0
f 0
dl 0
loc 81
rs 10
wmc 14

10 Methods

Rating   Name   Duplication   Size   Complexity  
A isString() 0 3 1
A getFunctionNames() 0 9 1
A isOpeningFuncParams() 0 3 1
A isExplanationFunction() 0 3 1
A isVariableOrFunction() 0 3 2
A isClosingFuncParams() 0 3 1
A isEncapsedString() 0 3 1
A isArgumentSeparator() 0 3 1
A parseDefinition() 0 17 3
A isTranslationFunction() 0 3 2
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