Completed
Push — master ( 6134fd...2d04cd )
by Tom
04:40 queued 02:18
created
src/Hook/DataFunction.php 3 patches
Doc Comments   +13 added lines patch added patch discarded remove patch
@@ -11,6 +11,10 @@  discard block
 block discarded – undo
11 11
 	private $data;
12 12
 	private $baseDir;
13 13
 
14
+	/**
15
+	 * @param string $baseDir
16
+	 * @param string $tss
17
+	 */
14 18
 	public function __construct(\SplObjectStorage $objectStorage, $data, $baseDir, $tss) {
15 19
 		$this->dataStorage = $objectStorage;
16 20
 		$this->data = $data;
@@ -79,6 +83,9 @@  discard block
 block discarded – undo
79 83
 		return $obj;
80 84
 	}
81 85
 
86
+	/**
87
+	 * @param \Transphporm\Parser\Value $valueParser
88
+	 */
82 89
 	private function traverseObj($part, $obj, $valueParser, $element) {
83 90
 		if (strpos($part, '(') !== false) {
84 91
 			$subObjParser = new \Transphporm\Parser\Value($obj, $valueParser, false);
@@ -143,6 +150,9 @@  discard block
 block discarded – undo
143 150
 		return $result;
144 151
 	}
145 152
 
153
+	/**
154
+	 * @param string $templateFile
155
+	 */
146 156
 	private function createDummyTemplateDoc(\DomElement $element, $templateFile) {		
147 157
 		$newDocument = new \DomDocument;
148 158
 		$root = $newDocument->createElement('template');
@@ -164,6 +174,9 @@  discard block
 block discarded – undo
164 174
 		return $newDocument;
165 175
 	}
166 176
 
177
+	/**
178
+	 * @param \DOMNode $baseElement
179
+	 */
167 180
 	private function loadTemplate($baseElement, $templateFile) {
168 181
 		$baseElement->setAttribute('transphpormbaselement', 'true');
169 182
 		//Load the template XML
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -117,7 +117,7 @@
 block discarded – undo
117 117
 		else $tss = '';
118 118
 		//Create a document to mimic the structure of the parent template
119 119
 		
120
-		$newDocument = $this->createDummyTemplateDoc($element, $this->baseDir . $val[0]);		
120
+		$newDocument = $this->createDummyTemplateDoc($element, $this->baseDir.$val[0]);		
121 121
 
122 122
 		//Build a new template using the $newDocument
123 123
 		$newTemplate = new \Transphporm\Builder($newDocument->saveXml(), $tss);
Please login to merge, or discard this patch.
Braces   +40 added lines, -16 removed lines patch added patch discarded remove patch
@@ -25,7 +25,9 @@  discard block
 block discarded – undo
25 25
 	/** Binds data to an element */
26 26
 	public function bind(\DomNode $element, $data, $type = 'data') {
27 27
 		//This is a bit of a hack to workaround #24, might need a better way of doing this if it causes a problem
28
-		if (is_array($data) && $this->isObjectArray($data)) $data = $data[0];
28
+		if (is_array($data) && $this->isObjectArray($data)) {
29
+			$data = $data[0];
30
+		}
29 31
 		$content = isset($this->dataStorage[$element]) ? $this->dataStorage[$element] : [];
30 32
 		$content[$type] = $data;
31 33
 		$this->dataStorage[$element] = $content;
@@ -49,7 +51,9 @@  discard block
 block discarded – undo
49 51
 	/** Returns the data that has been bound to $element, or, if no data is bound to $element climb the DOM tree to find the data bound to a parent node*/
50 52
 	public function getData(\DomElement $element = null, $type = 'data') {
51 53
 		while ($element) {
52
-			if (isset($this->dataStorage[$element]) && isset($this->dataStorage[$element][$type])) return $this->dataStorage[$element][$type];
54
+			if (isset($this->dataStorage[$element]) && isset($this->dataStorage[$element][$type])) {
55
+				return $this->dataStorage[$element][$type];
56
+			}
53 57
 			$element = $element->parentNode;
54 58
 		}
55 59
 		return $this->data;
@@ -68,13 +72,17 @@  discard block
 block discarded – undo
68 72
 		$valueParser = new \Transphporm\Parser\Value($this);
69 73
 
70 74
 		foreach ($parts as $part) {
71
-			if ($part === '') continue;
75
+			if ($part === '') {
76
+				continue;
77
+			}
72 78
 			$part = $valueParser->parse($part, $element)[0];
73 79
 			$funcResult = $this->traverseObj($part, $obj, $valueParser, $element);
74 80
 
75
-			if ($funcResult !== false) $obj = $funcResult;
76
-			
77
-			else $obj = $this->ifNull($obj, $part);
81
+			if ($funcResult !== false) {
82
+				$obj = $funcResult;
83
+			} else {
84
+				$obj = $this->ifNull($obj, $part);
85
+			}
78 86
 		}
79 87
 		return $obj;
80 88
 	}
@@ -83,14 +91,19 @@  discard block
 block discarded – undo
83 91
 		if (strpos($part, '(') !== false) {
84 92
 			$subObjParser = new \Transphporm\Parser\Value($obj, $valueParser, false);
85 93
 			return $subObjParser->parse($part, $element)[0];
94
+		} else if (method_exists($obj, $part)) {
95
+			return call_user_func([$obj, $part]);
96
+		} else {
97
+			return false;
86 98
 		}
87
-		else if (method_exists($obj, $part)) return call_user_func([$obj, $part]); 
88
-		else return false;
89 99
 	}
90 100
 
91 101
 	private function ifNull($obj, $key) {
92
-		if (is_array($obj)) return isset($obj[$key]) ? $obj[$key] : null;
93
-		else return isset($obj->$key) ? $obj->$key : null;
102
+		if (is_array($obj)) {
103
+			return isset($obj[$key]) ? $obj[$key] : null;
104
+		} else {
105
+			return isset($obj->$key) ? $obj->$key : null;
106
+		}
94 107
 	}
95 108
 
96 109
 	public function attr($val, $element) {
@@ -113,8 +126,11 @@  discard block
 block discarded – undo
113 126
 
114 127
 	public function template($val, \DomElement $element, $rules) {
115 128
 		//Check the nesting level... without this it will keep applying TSS to included templates forever in some cases
116
-		if (isset($rules['template-recursion']) && $rules['template-recursion'] == 'on') $tss = $this->tss;
117
-		else $tss = '';
129
+		if (isset($rules['template-recursion']) && $rules['template-recursion'] == 'on') {
130
+			$tss = $this->tss;
131
+		} else {
132
+			$tss = '';
133
+		}
118 134
 		//Create a document to mimic the structure of the parent template
119 135
 		
120 136
 		$newDocument = $this->createDummyTemplateDoc($element, $this->baseDir . $val[0]);		
@@ -133,10 +149,14 @@  discard block
 block discarded – undo
133 149
 		$result = [];
134 150
 		$xpath = new \DomXpath($doc);
135 151
 		$correspondingElement = $xpath->query('//*[@transphpormbaselement]')[0];
136
-		if (!$correspondingElement) $correspondingElement = $doc->documentElement;		
152
+		if (!$correspondingElement) {
153
+			$correspondingElement = $doc->documentElement;
154
+		}
137 155
 		foreach ($correspondingElement->childNodes as $child) {
138 156
 			$child = $child->cloneNode(true);
139
-			if ($child instanceof \DomElement) $child->setAttribute('transphporm', 'includedtemplate');
157
+			if ($child instanceof \DomElement) {
158
+				$child->setAttribute('transphporm', 'includedtemplate');
159
+			}
140 160
 
141 161
 			$result[] = $child;			
142 162
 		}		
@@ -155,8 +175,12 @@  discard block
 block discarded – undo
155 175
 			$firstChild = $root->firstChild;
156 176
 			$el = $el->cloneNode();
157 177
 			$newNode = $newDocument->importNode($el);
158
-			if ($baseElement === null) $baseElement = $newNode;
159
-			if ($firstChild) $newNode->appendChild($firstChild);
178
+			if ($baseElement === null) {
179
+				$baseElement = $newNode;
180
+			}
181
+			if ($firstChild) {
182
+				$newNode->appendChild($firstChild);
183
+			}
160 184
 			$root->appendChild($newNode);
161 185
 		}
162 186
 		while (($el = $el->parentNode)  instanceof \DomElement);	
Please login to merge, or discard this patch.
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, $rules = []) {
@@ -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, $rules)) !== self::IS_NOT_FUNCTION) $result = $this->appendToArray($result, $data);
64
-			else $result[] = trim($function);
63
+			if (($data = $this->getFunctionValue($func['name'], $func['params'], $element, $rules)) !== 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, $rules) {
71 74
 		if (($data = $this->callFunc($name, $params, $element, $rules)) !== self::IS_NOT_FUNCTION) {
72 75
 			return $data;
73
-		}
74
-		else if ($this->parent != null && ($data = $this->parent->callFunc($name, $params, $element, $rules)) !== self::IS_NOT_FUNCTION) {
76
+		} else if ($this->parent != null && ($data = $this->parent->callFunc($name, $params, $element, $rules)) !== 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, $rules) {
87 93
 		if ($name && $this->isCallable($this->dataFunction, $name)) {
88
-			if ($this->callParamsAsArray) return $this->dataFunction->$name($this->parse($params, $element), $element, $rules);	
89
-			else {
94
+			if ($this->callParamsAsArray) {
95
+				return $this->dataFunction->$name($this->parse($params, $element), $element, $rules);
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.
src/Hook/PropertyHook.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@
 block discarded – undo
23 23
 		if (!$this->pseudoMatcher->matches($element)) return;
24 24
 
25 25
 		foreach ($this->rules as $name => $value) {
26
-			$result = $this->callProperty($name, $element, $this->valueParser->parse(trim($value), $element,$this->rules)) ;
26
+			$result = $this->callProperty($name, $element, $this->valueParser->parse(trim($value), $element, $this->rules));
27 27
 			if ($result === false) break;
28 28
 		}
29 29
 	}
Please login to merge, or discard this patch.