Completed
Push — master ( 1099f2...b313d2 )
by Tom
10:52 queued 20s
created
src/Parser/StringExtractor.php 1 patch
Braces   +6 added lines, -2 removed lines patch added patch discarded remove patch
@@ -21,7 +21,9 @@  discard block
 block discarded – undo
21 21
 		$strings = [];
22 22
 		while (isset($str[$pos]) && ($pos = strpos($str, '"', $pos)) !== false) {
23 23
 			$end = strpos($str, '"', $pos+1);
24
-			if (!$end) break;
24
+			if (!$end) {
25
+				break;
26
+			}
25 27
 			$end = $this->getNextPosEscaped($str, '\\', '"', $end);
26 28
 			$strings['$___STR' . ++$num] = substr($str, $pos, $end-$pos+1);
27 29
 			$str = substr_replace($str, '$___STR' . $num, $pos, $end-$pos+1);
@@ -31,7 +33,9 @@  discard block
 block discarded – undo
31 33
 	}
32 34
 
33 35
 	private function getNextPosEscaped($str, $escape, $chr, $start) {
34
-		while ($str[$start-1] == $escape) $start = strpos($str, $chr, $start+1);
36
+		while ($str[$start-1] == $escape) {
37
+			$start = strpos($str, $chr, $start+1);
38
+		}
35 39
 		return $start;
36 40
 	}
37 41
 
Please login to merge, or discard this patch.
src/Property/Content.php 1 patch
Braces   +24 added lines, -10 removed lines patch added patch discarded remove patch
@@ -18,23 +18,32 @@  discard block
 block discarded – undo
18 18
 	}
19 19
 
20 20
 	public function run($value, \DomElement $element, array $rules, \Transphporm\Hook\PseudoMatcher $pseudoMatcher, array $properties = []) {
21
-		if ($this->shouldRun($element) == false) return;
21
+		if ($this->shouldRun($element) == false) {
22
+			return;
23
+		}
22 24
 			
23 25
 		$value = $this->formatter->format($value, $rules);
24 26
 		if (!$this->processPseudo($value, $element, $pseudoMatcher)) {
25 27
 			//Remove the current contents
26 28
 			$this->removeAllChildren($element);
27 29
 			//Now make a text node
28
-			if ($this->getContentMode($rules) === 'replace') $this->replaceContent($element, $value);
29
-			else $this->appendContent($element, $value);
30
+			if ($this->getContentMode($rules) === 'replace') {
31
+				$this->replaceContent($element, $value);
32
+			} else {
33
+				$this->appendContent($element, $value);
34
+			}
30 35
 		}
31 36
 	}
32 37
 
33 38
 	private function shouldRun($element) {
34
-		if ($element->getAttribute('transphporm') === 'remove') return false;
39
+		if ($element->getAttribute('transphporm') === 'remove') {
40
+			return false;
41
+		}
35 42
 
36 43
 		while (!($element instanceof \DomDocument) && $element->parentNode) {
37
-			if ($element->getAttribute('transphporm') == 'includedtemplate') return false;
44
+			if ($element->getAttribute('transphporm') == 'includedtemplate') {
45
+				return false;
46
+			}
38 47
 			$element = $element->parentNode;
39 48
 		}
40 49
 
@@ -60,9 +69,10 @@  discard block
 block discarded – undo
60 69
 			if ($n instanceof \DomElement) {
61 70
 				$new = $document->importNode($n, true);
62 71
 				$new->setAttribute('transphporm', 'added');
63
-			}
64
-			else {
65
-				if ($n instanceof \DomText) $n = $n->nodeValue;
72
+			} else {
73
+				if ($n instanceof \DomText) {
74
+					$n = $n->nodeValue;
75
+				}
66 76
 				$new = $document->createElement('text');
67 77
 				$new->appendChild($document->createTextNode($n));
68 78
 				$new->setAttribute('transphporm', 'text');
@@ -98,7 +108,9 @@  discard block
 block discarded – undo
98 108
 		while ($e = $e->previousSibling && !in_array($e->getAttribute('transphporm'), [null, 'remove'])) {
99 109
 			$remove[] = $e;
100 110
 		}
101
-		foreach ($remove as $r) $r->parentNode->removeChild($r);
111
+		foreach ($remove as $r) {
112
+			$r->parentNode->removeChild($r);
113
+		}
102 114
 	}
103 115
 
104 116
 	private function replaceContent($element, $content) {
@@ -117,6 +129,8 @@  discard block
 block discarded – undo
117 129
 	}
118 130
 	
119 131
 	private function removeAllChildren($element) {
120
-		while ($element->hasChildNodes()) $element->removeChild($element->firstChild);
132
+		while ($element->hasChildNodes()) {
133
+			$element->removeChild($element->firstChild);
134
+		}
121 135
 	}
122 136
 }
123 137
\ No newline at end of file
Please login to merge, or discard this patch.
src/Hook/DataFunction.php 1 patch
Braces   +29 added lines, -12 removed lines patch added patch discarded remove patch
@@ -21,7 +21,9 @@  discard block
 block discarded – undo
21 21
 	/** Binds data to an element */
22 22
 	public function bind(\DomNode $element, $data, $type = 'data') {
23 23
 		//This is a bit of a hack to workaround #24, might need a better way of doing this if it causes a problem
24
-		if (is_array($data) && $this->isObjectArray($data)) $data = $data[0];
24
+		if (is_array($data) && $this->isObjectArray($data)) {
25
+			$data = $data[0];
26
+		}
25 27
 		$content = isset($this->dataStorage[$element]) ? $this->dataStorage[$element] : [];
26 28
 		$content[$type] = $data;
27 29
 		$this->dataStorage[$element] = $content;
@@ -45,7 +47,9 @@  discard block
 block discarded – undo
45 47
 	/** 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*/
46 48
 	public function getData(\DomElement $element = null, $type = 'data') {
47 49
 		while ($element) {
48
-			if (isset($this->dataStorage[$element]) && isset($this->dataStorage[$element][$type])) return $this->dataStorage[$element][$type];
50
+			if (isset($this->dataStorage[$element]) && isset($this->dataStorage[$element][$type])) {
51
+				return $this->dataStorage[$element][$type];
52
+			}
49 53
 			$element = $element->parentNode;
50 54
 		}
51 55
 		return $this->data;
@@ -64,13 +68,17 @@  discard block
 block discarded – undo
64 68
 		$valueParser = new \Transphporm\Parser\Value($this);
65 69
 
66 70
 		foreach ($parts as $part) {
67
-			if ($part === '') continue;
71
+			if ($part === '') {
72
+				continue;
73
+			}
68 74
 			$part = $valueParser->parse($part, $element)[0];
69 75
 			$funcResult = $this->traverseObj($part, $obj, $valueParser, $element);
70 76
 			
71
-			if ($funcResult !== false) $obj = $funcResult;
72
-			
73
-			else $obj = $this->ifNull($obj, $part);
77
+			if ($funcResult !== false) {
78
+				$obj = $funcResult;
79
+			} else {
80
+				$obj = $this->ifNull($obj, $part);
81
+			}
74 82
 		}
75 83
 		return $obj;
76 84
 	}
@@ -79,14 +87,19 @@  discard block
 block discarded – undo
79 87
 		if (strpos($part, '(') !== false) {
80 88
 			$subObjParser = new \Transphporm\Parser\Value($obj, $valueParser, false);
81 89
 			return $subObjParser->parse($part, $element);
90
+		} else if (method_exists($obj, $part)) {
91
+			return call_user_func([$obj, $part]);
92
+		} else {
93
+			return false;
82 94
 		}
83
-		else if (method_exists($obj, $part)) return call_user_func([$obj, $part]); 
84
-		else return false;
85 95
 	}
86 96
 
87 97
 	private function ifNull($obj, $key) {
88
-		if (is_array($obj)) return isset($obj[$key]) ? $obj[$key] : null;
89
-		else return isset($obj->$key) ? $obj->$key : null;
98
+		if (is_array($obj)) {
99
+			return isset($obj[$key]) ? $obj[$key] : null;
100
+		} else {
101
+			return isset($obj->$key) ? $obj->$key : null;
102
+		}
90 103
 	}
91 104
 
92 105
 	public function attr($val, $element) {
@@ -112,7 +125,9 @@  discard block
 block discarded – undo
112 125
 
113 126
 		$doc = $newTemplate->output($data, true)->body;
114 127
 
115
-		if (isset($val[1])) return $this->templateSubsection($val[1], $doc, $element);
128
+		if (isset($val[1])) {
129
+			return $this->templateSubsection($val[1], $doc, $element);
130
+		}
116 131
 		
117 132
 		$newNode = $element->ownerDocument->importNode($doc->documentElement, true);
118 133
 	//	$this->bind($newNode, $data);
@@ -121,7 +136,9 @@  discard block
 block discarded – undo
121 136
 		if ($newNode->tagName === 'template') {
122 137
 			foreach ($newNode->childNodes as $node) {
123 138
 				$clone = $node->cloneNode(true);
124
-				if ($clone instanceof \DomElement) $clone->setAttribute('transphporm', 'includedtemplate');
139
+				if ($clone instanceof \DomElement) {
140
+					$clone->setAttribute('transphporm', 'includedtemplate');
141
+				}
125 142
 				$result[] = $clone;
126 143
 			}
127 144
 		}		
Please login to merge, or discard this patch.