@@ -33,7 +33,9 @@ discard block |
||
33 | 33 | $rules = $this->writeRule($rules, $newRules); |
34 | 34 | } |
35 | 35 | //there may be processing instructions at the end |
36 | - if ($processing = $this->processingInstructions($this->tss, $pos, strlen($this->tss), count($rules)+$indexStart)) $rules = array_merge($rules, $processing['rules']); |
|
36 | + if ($processing = $this->processingInstructions($this->tss, $pos, strlen($this->tss), count($rules)+$indexStart)) { |
|
37 | + $rules = array_merge($rules, $processing['rules']); |
|
38 | + } |
|
37 | 39 | usort($rules, [$this, 'sortRules']); |
38 | 40 | return $rules; |
39 | 41 | } |
@@ -69,8 +71,7 @@ discard block |
||
69 | 71 | $pos = strpos($tss, ';', $spacePos); |
70 | 72 | $args = substr($tss, $spacePos+1, $pos-$spacePos-1); |
71 | 73 | $rules = array_merge($rules, $this->$funcName($args, $indexStart)); |
72 | - } |
|
73 | - else { |
|
74 | + } else { |
|
74 | 75 | break; |
75 | 76 | } |
76 | 77 | } |
@@ -85,7 +86,9 @@ discard block |
||
85 | 86 | |
86 | 87 | private function sortRules($a, $b) { |
87 | 88 | //If they have the same depth, compare on index |
88 | - if ($a->depth === $b->depth) return $a->index < $b->index ? -1 : 1; |
|
89 | + if ($a->depth === $b->depth) { |
|
90 | + return $a->index < $b->index ? -1 : 1; |
|
91 | + } |
|
89 | 92 | |
90 | 93 | return ($a->depth < $b->depth) ? -1 : 1; |
91 | 94 | } |
@@ -94,7 +97,9 @@ discard block |
||
94 | 97 | $pos = 0; |
95 | 98 | while (($pos = strpos($str, $open, $pos)) !== false) { |
96 | 99 | $end = strpos($str, $close, $pos); |
97 | - if ($end === false) break; |
|
100 | + if ($end === false) { |
|
101 | + break; |
|
102 | + } |
|
98 | 103 | $str = substr_replace($str, '', $pos, $end-$pos+2); |
99 | 104 | } |
100 | 105 | |
@@ -107,7 +112,9 @@ discard block |
||
107 | 112 | $return = []; |
108 | 113 | |
109 | 114 | foreach ($rules as $rule) { |
110 | - if (trim($rule) === '') continue; |
|
115 | + if (trim($rule) === '') { |
|
116 | + continue; |
|
117 | + } |
|
111 | 118 | $parts = explode(':', $rule, 2); |
112 | 119 | |
113 | 120 | $parts[1] = $stringExtractor->rebuild($parts[1]); |
@@ -32,8 +32,9 @@ discard block |
||
32 | 32 | $params = $bracketMatcher->match('(', ')'); |
33 | 33 | |
34 | 34 | return ['name' => $name, 'params' => $params, 'endPoint' => $bracketMatcher->getClosePos()]; |
35 | + } else { |
|
36 | + return ['name' => null, 'params' => $function, 'endPoint' => strlen($function)]; |
|
35 | 37 | } |
36 | - else return ['name' => null, 'params' => $function, 'endPoint' => strlen($function)]; |
|
37 | 38 | } |
38 | 39 | |
39 | 40 | public function parse($function, \DomElement $element) { |
@@ -54,13 +55,15 @@ discard block |
||
54 | 55 | if ($function && in_array($function[0], ['\'', '"'])) { |
55 | 56 | $finalPos = $this->findMatchingPos($function, $function[0]); |
56 | 57 | $result[] = $this->extractQuotedString($function[0], $function); |
57 | - } |
|
58 | - else { |
|
58 | + } else { |
|
59 | 59 | $func = $this->parseFunction($function); |
60 | 60 | $finalPos = $func['endPoint']; |
61 | 61 | |
62 | - if (($data = $this->getFunctionValue($func['name'], $func['params'], $element)) !== false) $result = $this->appendToArray($result, $data); |
|
63 | - else $result[] = trim($function); |
|
62 | + if (($data = $this->getFunctionValue($func['name'], $func['params'], $element)) !== false) { |
|
63 | + $result = $this->appendToArray($result, $data); |
|
64 | + } else { |
|
65 | + $result[] = trim($function); |
|
66 | + } |
|
64 | 67 | } |
65 | 68 | $remaining = trim(substr($function, $finalPos+1)); |
66 | 69 | return $this->parseNextValue($remaining, $result, $element); |
@@ -69,23 +72,27 @@ discard block |
||
69 | 72 | private function getFunctionValue($name, $params, $element) { |
70 | 73 | if (($data = $this->callFunc($name, $params, $element)) !== false) { |
71 | 74 | return $data; |
72 | - } |
|
73 | - else if ($this->parent != null && ($data = $this->parent->callFunc($name, $params, $element)) !== false) { |
|
75 | + } else if ($this->parent != null && ($data = $this->parent->callFunc($name, $params, $element)) !== false) { |
|
74 | 76 | return $data; |
77 | + } else { |
|
78 | + return false; |
|
75 | 79 | } |
76 | - else return false; |
|
77 | 80 | } |
78 | 81 | |
79 | 82 | private function appendToArray($array, $value) { |
80 | - if (is_array($value)) $array += $value; |
|
81 | - else $array[] = $value; |
|
83 | + if (is_array($value)) { |
|
84 | + $array += $value; |
|
85 | + } else { |
|
86 | + $array[] = $value; |
|
87 | + } |
|
82 | 88 | return $array; |
83 | 89 | } |
84 | 90 | |
85 | 91 | private function callFunc($name, $params, $element) { |
86 | 92 | if ($name && $this->isCallable($this->dataFunction, $name)) { |
87 | - if ($this->callParamsAsArray) return $this->dataFunction->$name($this->parse($params, $element), $element); |
|
88 | - else { |
|
93 | + if ($this->callParamsAsArray) { |
|
94 | + return $this->dataFunction->$name($this->parse($params, $element), $element); |
|
95 | + } else { |
|
89 | 96 | return $this->callFuncOnObject($this->dataFunction, $name, $this->parse($params, $element)); |
90 | 97 | } |
91 | 98 | } |
@@ -102,14 +109,21 @@ discard block |
||
102 | 109 | foreach ($params as $param) { |
103 | 110 | $stringExtractor = new StringExtractor($param); |
104 | 111 | $parts = explode(',', $stringExtractor); |
105 | - foreach ($parts as $part) $args[] = $stringExtractor->rebuild($part); |
|
112 | + foreach ($parts as $part) { |
|
113 | + $args[] = $stringExtractor->rebuild($part); |
|
114 | + } |
|
115 | + } |
|
116 | + if (isset($obj->$func) && is_callable($obj->$func)) { |
|
117 | + return call_user_func_array($obj->$func, $args); |
|
118 | + } else { |
|
119 | + return call_user_func_array([$obj, $func], $args); |
|
106 | 120 | } |
107 | - if (isset($obj->$func) && is_callable($obj->$func)) return call_user_func_array($obj->$func, $args); |
|
108 | - else return call_user_func_array([$obj, $func], $args); |
|
109 | 121 | } |
110 | 122 | |
111 | 123 | private function parseNextValue($remaining, $result, $element) { |
112 | - if (strlen($remaining) > 0 && $remaining[0] == ',') $result = array_merge($result, $this->parse(trim(substr($remaining, 1)), $element)); |
|
124 | + if (strlen($remaining) > 0 && $remaining[0] == ',') { |
|
125 | + $result = array_merge($result, $this->parse(trim(substr($remaining, 1)), $element)); |
|
126 | + } |
|
113 | 127 | return $result; |
114 | 128 | } |
115 | 129 | |
@@ -117,8 +131,9 @@ discard block |
||
117 | 131 | $pos = $start+1; |
118 | 132 | $end = 0; |
119 | 133 | while ($end = strpos($string, $char, $pos)) { |
120 | - if ($string[$end-1] === $escape) $pos = $end+1; |
|
121 | - else { |
|
134 | + if ($string[$end-1] === $escape) { |
|
135 | + $pos = $end+1; |
|
136 | + } else { |
|
122 | 137 | break; |
123 | 138 | } |
124 | 139 | } |