|
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
|
|
|
/** |
|
10
|
|
|
* @var array<string,bool> |
|
11
|
|
|
*/ |
|
12
|
|
|
private static $explanationFunctions = array( |
|
13
|
|
|
'tex' => true, |
|
14
|
|
|
'ptex' => true, |
|
15
|
|
|
'ptexs' => true |
|
16
|
|
|
); |
|
17
|
|
|
|
|
18
|
|
|
protected function parseDefinition() : void |
|
19
|
|
|
{ |
|
20
|
|
|
// some entries are strings, like parentheses, semicolons and the like. |
|
21
|
|
|
if(is_string($this->definition)) |
|
22
|
|
|
{ |
|
23
|
|
|
$this->token = $this->definition; |
|
24
|
|
|
$this->value = null; |
|
25
|
|
|
|
|
26
|
|
|
if(isset($this->parentToken)) { |
|
27
|
|
|
$this->line = $this->parentToken->getLine(); |
|
|
|
|
|
|
28
|
|
|
} |
|
29
|
|
|
} |
|
30
|
|
|
else |
|
31
|
|
|
{ |
|
32
|
|
|
$this->token = token_name($this->definition[0]); |
|
33
|
|
|
$this->value = $this->definition[1]; |
|
34
|
|
|
$this->line = $this->definition[2]; |
|
35
|
|
|
} |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @return string[] |
|
40
|
|
|
*/ |
|
41
|
|
|
public function getFunctionNames() : array |
|
42
|
|
|
{ |
|
43
|
|
|
return array( |
|
44
|
|
|
't', |
|
45
|
|
|
'pt', |
|
46
|
|
|
'pts', |
|
47
|
|
|
'tex', |
|
48
|
|
|
'ptex', |
|
49
|
|
|
'ptexs' |
|
50
|
|
|
); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function isOpeningFuncParams() : bool |
|
54
|
|
|
{ |
|
55
|
|
|
return $this->getToken() === '('; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
public function isClosingFuncParams() : bool |
|
59
|
|
|
{ |
|
60
|
|
|
return $this->getToken() === ')'; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public function isString() : bool |
|
64
|
|
|
{ |
|
65
|
|
|
return $this->token === 'T_STRING'; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
public function isEncapsedString() : bool |
|
69
|
|
|
{ |
|
70
|
|
|
return $this->token === 'T_CONSTANT_ENCAPSED_STRING'; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
public function isTranslationFunction() : bool |
|
74
|
|
|
{ |
|
75
|
|
|
return $this->isString() && isset($this->nameLookup[$this->getValue()]); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
public function isVariableOrFunction() : bool |
|
79
|
|
|
{ |
|
80
|
|
|
return $this->token === 'T_VARIABLE' || $this->token === 'T_FUNCTION'; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
public function isExplanationFunction() : bool |
|
84
|
|
|
{ |
|
85
|
|
|
return isset(self::$explanationFunctions[$this->getValue()]); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
public function isArgumentSeparator() : bool |
|
89
|
|
|
{ |
|
90
|
|
|
return $this->getToken() === ','; |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.