Conditions | 32 |
Paths | 5403 |
Total Lines | 91 |
Code Lines | 48 |
Lines | 9 |
Ratio | 9.89 % |
Changes | 4 | ||
Bugs | 2 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
27 | public function parseTokens($tokens, $element, $data) { |
||
28 | $result = []; |
||
29 | $mode = Tokenizer::ARG; |
||
30 | $last = null; |
||
31 | |||
32 | if (empty($tokens)) return [$data]; |
||
33 | |||
34 | foreach ($tokens as $token) { |
||
35 | if (is_string($token)) throw new \Exception($token); |
||
36 | |||
37 | if (in_array($token['type'], [Tokenizer::NOT, Tokenizer::EQUALS])) { |
||
38 | // ($last !== null) $result = $this->processValue($result, $mode, $last); |
||
39 | |||
40 | $result = $this->processLast($last, $result, $mode, $data); |
||
41 | |||
42 | if ($mode == Tokenizer::NOT && $token['type'] == Tokenizer::EQUALS) { |
||
43 | $mode = Tokenizer::NOT; |
||
44 | } |
||
45 | else $mode = $token['type']; |
||
46 | } |
||
47 | |||
48 | if ($token['type'] === Tokenizer::DOT) { |
||
49 | View Code Duplication | if ($last !== null) { |
|
50 | if (isset($data->$last)) $data = $data->$last; |
||
51 | else if (is_array($data) && isset($data[$last])) $data = $data[$last]; |
||
52 | } |
||
53 | else $data = array_pop($result); |
||
54 | |||
55 | $last = null; |
||
56 | } |
||
57 | |||
58 | if ($token['type'] == Tokenizer::OPEN_SQUARE_BRACKET) { |
||
59 | if ($last !== null) { |
||
60 | if (isset($data->$last)) $data = $data->$last; |
||
61 | else if (is_array($data) && isset($data[$last])) $data = $data[$last]; |
||
62 | } |
||
63 | |||
64 | $last = $this->parseTokens($token['value'], $element, null)[0]; |
||
65 | } |
||
66 | |||
67 | if (in_array($token['type'], [Tokenizer::ARG, Tokenizer::CONCAT])) { |
||
68 | $mode = $token['type']; |
||
69 | //if ($last !== null) $result = $this->processValue($result, $mode, $last); |
||
70 | $result = $this->processLast($last, $result, $mode, $data); |
||
71 | } |
||
72 | |||
73 | if ($token['type'] === Tokenizer::STRING) { |
||
74 | $result = $this->processValue($result, $mode, $token['value']); |
||
75 | } |
||
76 | |||
77 | if (in_array($token['type'], [Tokenizer::NAME, Tokenizer::NUMERIC, Tokenizer::BOOL])) { |
||
78 | $last = $token['value']; |
||
79 | } |
||
80 | |||
81 | if ($token['type'] == Tokenizer::OPEN_BRACKET) { |
||
82 | |||
83 | if ($this->data instanceof \Transphporm\Functionset && ($last == 'data' || $last == 'iteration' || $last == 'attr')) { |
||
84 | $result = $this->processValue($result, $mode, $this->data->$last($token['value'], $element)); |
||
85 | |||
86 | foreach ($result as $i => $value) { |
||
87 | View Code Duplication | if (is_array($data)) { |
|
88 | if (isset($data[$value])) $result[$i] = $data[$value]; |
||
89 | } |
||
90 | else if (is_scalar($value) && isset($data->$value)) $result[$i] = $data->$value; |
||
91 | } |
||
92 | $last = null; |
||
93 | } |
||
94 | else if ($data instanceof \Transphporm\Functionset) { |
||
95 | $result = $this->processValue($result, $mode, $data->$last($token['value'], $element)); |
||
96 | $last = null; |
||
97 | } |
||
98 | else { |
||
99 | $args = $this->parseTokens($token['value'], $element, $data); |
||
100 | if ($args[0] == $data) $args = []; |
||
101 | $funcResult = $this->callFunc($last, $args, $element, $data); |
||
102 | $result = $this->processValue($result, $mode, $funcResult); |
||
103 | $last = null; |
||
104 | } |
||
105 | } |
||
106 | /* |
||
107 | if ($token['type'] == Tokenizer::OPEN_SQUARE_BRACKET) { |
||
108 | if ($this->autoLookup === true) { |
||
109 | $result = $this->processValue($result, $mode, $data->$last($token['value'], $element)); |
||
110 | $last = null; |
||
111 | |||
112 | } |
||
113 | }//*/ |
||
114 | } |
||
115 | |||
116 | return $this->processLast($last, $result, $mode, $data); |
||
117 | } |
||
118 | |||
165 |
This check marks private properties in classes that are never used. Those properties can be removed.