Completed
Push — master ( d23d52...653716 )
by Tom
02:42
created
src/Parser/Value.php 1 patch
Braces   +33 added lines, -18 removed lines patch added patch discarded remove patch
@@ -33,8 +33,9 @@  discard block
 block discarded – undo
33 33
 			$params = $bracketMatcher->match('(', ')');
34 34
 			
35 35
 			return ['name' => $name, 'params' => $params, 'endPoint' => $bracketMatcher->getClosePos()];
36
+		} else {
37
+			return ['name' => null, 'params' => $function, 'endPoint' => strlen($function)];
36 38
 		}
37
-		else return ['name' => null, 'params' => $function, 'endPoint' => strlen($function)];
38 39
 	}
39 40
 
40 41
 	public function parse($function, \DomElement $element) {
@@ -55,13 +56,15 @@  discard block
 block discarded – undo
55 56
 		if ($function && in_array($function[0], ['\'', '"'])) {
56 57
 			$finalPos = $this->findMatchingPos($function, $function[0]);
57 58
 			$result[] = $this->extractQuotedString($function[0], $function);
58
-		}
59
-		else {
59
+		} else {
60 60
 			$func = $this->parseFunction($function);
61 61
 			$finalPos = $func['endPoint'];			
62 62
 
63
-			if (($data = $this->getFunctionValue($func['name'], $func['params'], $element)) !== self::IS_NOT_FUNCTION) $result = $this->appendToArray($result, $data);
64
-			else $result[] = trim($function);
63
+			if (($data = $this->getFunctionValue($func['name'], $func['params'], $element)) !== self::IS_NOT_FUNCTION) {
64
+				$result = $this->appendToArray($result, $data);
65
+			} else {
66
+				$result[] = trim($function);
67
+			}
65 68
 		}
66 69
 		$remaining = trim(substr($function, $finalPos+1));
67 70
 		return $this->parseNextValue($remaining, $result, $element);
@@ -70,23 +73,27 @@  discard block
 block discarded – undo
70 73
 	private function getFunctionValue($name, $params, $element) {
71 74
 		if (($data = $this->callFunc($name, $params, $element)) !== self::IS_NOT_FUNCTION) {
72 75
 			return $data;
73
-		}
74
-		else if ($this->parent != null && ($data = $this->parent->callFunc($name, $params, $element)) !== self::IS_NOT_FUNCTION) {
76
+		} else if ($this->parent != null && ($data = $this->parent->callFunc($name, $params, $element)) !== self::IS_NOT_FUNCTION) {
75 77
 			return $data;
78
+		} else {
79
+			return self::IS_NOT_FUNCTION;
76 80
 		}
77
-		else return self::IS_NOT_FUNCTION;
78 81
 	}
79 82
 
80 83
 	private function appendToArray($array, $value) {
81
-		if (is_array($value)) $array += $value;
82
-		else $array[] = $value;
84
+		if (is_array($value)) {
85
+			$array += $value;
86
+		} else {
87
+			$array[] = $value;
88
+		}
83 89
 		return $array;
84 90
 	}
85 91
 
86 92
 	private function callFunc($name, $params, $element) {
87 93
 		if ($name && $this->isCallable($this->dataFunction, $name)) {
88
-			if ($this->callParamsAsArray) return $this->dataFunction->$name($this->parse($params, $element), $element);	
89
-			else {
94
+			if ($this->callParamsAsArray) {
95
+				return $this->dataFunction->$name($this->parse($params, $element), $element);
96
+			} else {
90 97
 				return $this->callFuncOnObject($this->dataFunction, $name, $this->parse($params, $element));
91 98
 			}
92 99
 		}
@@ -103,14 +110,21 @@  discard block
 block discarded – undo
103 110
 		foreach ($params as $param) {
104 111
 			$stringExtractor = new StringExtractor($param);
105 112
 			$parts = explode(',', $stringExtractor);
106
-			foreach ($parts as $part) $args[] = $stringExtractor->rebuild($part);
113
+			foreach ($parts as $part) {
114
+				$args[] = $stringExtractor->rebuild($part);
115
+			}
116
+		}
117
+		if (isset($obj->$func) && is_callable($obj->$func)) {
118
+			return call_user_func_array($obj->$func, $args);
119
+		} else {
120
+			return call_user_func_array([$obj, $func], $args);
107 121
 		}
108
-		if (isset($obj->$func) && is_callable($obj->$func)) return call_user_func_array($obj->$func, $args);
109
-		else return call_user_func_array([$obj, $func], $args);
110 122
 	}
111 123
 
112 124
 	private function parseNextValue($remaining, $result, $element) {
113
-		if (strlen($remaining) > 0 && $remaining[0] == ',') $result = array_merge($result, $this->parse(trim(substr($remaining, 1)), $element));
125
+		if (strlen($remaining) > 0 && $remaining[0] == ',') {
126
+			$result = array_merge($result, $this->parse(trim(substr($remaining, 1)), $element));
127
+		}
114 128
 		return $result;
115 129
 	}
116 130
 	
@@ -118,8 +132,9 @@  discard block
 block discarded – undo
118 132
 		$pos = $start+1;
119 133
 		$end = 0;
120 134
 		while ($end = strpos($string, $char, $pos)) {
121
-			if ($string[$end-1] === $escape) $pos = $end+1;
122
-			else {
135
+			if ($string[$end-1] === $escape) {
136
+				$pos = $end+1;
137
+			} else {
123 138
 				break;
124 139
 			}
125 140
 		}
Please login to merge, or discard this patch.