Completed
Push — master ( f8e36b...235894 )
by Tom
02:30
created
src/Hook/DataFunction.php 1 patch
Braces   +25 added lines, -9 removed lines patch added patch discarded remove patch
@@ -22,7 +22,9 @@  discard block
 block discarded – undo
22 22
 	/** Binds data to an element */
23 23
 	public function bind(\DomElement $element, $data, $type = 'data') {
24 24
 		//This is a bit of a hack to workaround #24, might need a better way of doing this if it causes a problem
25
-		if (is_array($data) && $this->isObjectArray($data)) $data = $data[0];
25
+		if (is_array($data) && $this->isObjectArray($data)) {
26
+			$data = $data[0];
27
+		}
26 28
 		$content = isset($this->dataStorage[$element]) ? $this->dataStorage[$element] : [];
27 29
 		$content[$type] = $data;
28 30
 		$this->dataStorage[$element] = $content;
@@ -46,7 +48,9 @@  discard block
 block discarded – undo
46 48
 	/** 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*/
47 49
 	private function getData(\DomElement $element = null, $type = 'data') {
48 50
 		while ($element) {
49
-			if (isset($this->dataStorage[$element]) && isset($this->dataStorage[$element][$type])) return $this->dataStorage[$element][$type];
51
+			if (isset($this->dataStorage[$element]) && isset($this->dataStorage[$element][$type])) {
52
+				return $this->dataStorage[$element][$type];
53
+			}
50 54
 			$element = $element->parentNode;
51 55
 		}
52 56
 		return $this->data;
@@ -64,17 +68,25 @@  discard block
 block discarded – undo
64 68
 		$obj = $data;
65 69
 		$valueParser = new \Transphporm\Parser\Value($this);
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
-			if (is_callable([$obj, $part])) $obj = call_user_func([$obj, $part]); 
70
-			else $obj = $this->ifNull($obj, $part);
75
+			if (is_callable([$obj, $part])) {
76
+				$obj = call_user_func([$obj, $part]);
77
+			} else {
78
+				$obj = $this->ifNull($obj, $part);
79
+			}
71 80
 		}
72 81
 		return $obj;
73 82
 	}
74 83
 
75 84
 	private function ifNull($obj, $key) {
76
-		if (is_array($obj)) return isset($obj[$key]) ? $obj[$key] : null;
77
-		else return isset($obj->$key) ? $obj->$key : null;
85
+		if (is_array($obj)) {
86
+			return isset($obj[$key]) ? $obj[$key] : null;
87
+		} else {
88
+			return isset($obj->$key) ? $obj->$key : null;
89
+		}
78 90
 	}
79 91
 
80 92
 	public function attr($val, $element) {
@@ -100,14 +112,18 @@  discard block
 block discarded – undo
100 112
 
101 113
 		$doc = $newTemplate->output([], true)->body;
102 114
 
103
-		if (isset($val[1])) return $this->templateSubsection($val[1], $doc, $element);
115
+		if (isset($val[1])) {
116
+			return $this->templateSubsection($val[1], $doc, $element);
117
+		}
104 118
 		
105 119
 		$newNode = $element->ownerDocument->importNode($doc->documentElement, true);
106 120
 
107 121
 		$result = [];
108 122
 
109 123
 		if ($newNode->tagName === 'template') {
110
-			foreach ($newNode->childNodes as $node) $result[] = $node->cloneNode(true);
124
+			foreach ($newNode->childNodes as $node) {
125
+				$result[] = $node->cloneNode(true);
126
+			}
111 127
 		}		
112 128
 		//else $result[] = $newNode;
113 129
 
Please login to merge, or discard this patch.
src/Hook/PseudoMatcher.php 1 patch
Braces   +29 added lines, -11 removed lines patch added patch discarded remove patch
@@ -29,16 +29,22 @@  discard block
 block discarded – undo
29 29
 		$close = strpos($string, $closingChr, $open);
30 30
 
31 31
 		$cPos = $open+1;
32
-		while (($cPos = strpos($string, $openChr, $cPos+1)) !== false && $cPos < $close) $close = strpos($string, $closingChr, $close+1);
32
+		while (($cPos = strpos($string, $openChr, $cPos+1)) !== false && $cPos < $close) {
33
+			$close = strpos($string, $closingChr, $close+1);
34
+		}
33 35
 
34 36
 		return substr($string, $open+1, $close-$open-1);
35 37
 	}
36 38
 	
37 39
 	private function attribute($pseudo, $element) {
38
-		if (strpos($pseudo, '=') === false) return true;
40
+		if (strpos($pseudo, '=') === false) {
41
+			return true;
42
+		}
39 43
 
40 44
 		$pos = strpos($pseudo, '[');
41
-		if ($pos === false) return true;
45
+		if ($pos === false) {
46
+			return true;
47
+		}
42 48
 		
43 49
 		$name = substr($pseudo, 0, $pos);
44 50
 		$criteria = $this->betweenBrackets($pseudo, '[', ']');
@@ -56,16 +62,21 @@  discard block
 block discarded – undo
56 62
 	}
57 63
 
58 64
 	private function parseValue($value) {
59
-		if ($value == 'true') return true;
60
-		else if ($value == 'false') return false;
61
-		else return $value;
65
+		if ($value == 'true') {
66
+			return true;
67
+		} else if ($value == 'false') {
68
+			return false;
69
+		} else {
70
+			return $value;
71
+		}
62 72
 	}
63 73
 
64 74
 	private function getOperator($field) {
65 75
 		if ($field[strlen($field)-1] == '!') {
66 76
 			return '!';
77
+		} else {
78
+			return '';
67 79
 		}
68
-		else return '';
69 80
 	}
70 81
 
71 82
 	private function nth($pseudo, $element) {
@@ -73,8 +84,11 @@  discard block
 block discarded – undo
73 84
 			$criteria = $this->getBetween($pseudo, '(', ')');
74 85
 			$num = $this->getBetween($element->getNodePath(), '[', ']');
75 86
 			
76
-			if (is_callable([$this, $criteria])) return $this->$criteria($num);
77
-			else return $num == $criteria;
87
+			if (is_callable([$this, $criteria])) {
88
+				return $this->$criteria($num);
89
+			} else {
90
+				return $num == $criteria;
91
+			}
78 92
 			
79 93
 		}
80 94
 		return true;
@@ -94,7 +108,9 @@  discard block
 block discarded – undo
94 108
 	public function header($element)  {
95 109
 		if ($this->matches($element)) {
96 110
 			foreach ($this->pseudo as $pseudo) {
97
-				if (strpos($pseudo, 'header') === 0) return $this->getBetween($pseudo, '[', ']');
111
+				if (strpos($pseudo, 'header') === 0) {
112
+					return $this->getBetween($pseudo, '[', ']');
113
+				}
98 114
 			}
99 115
 		}
100 116
 	}
@@ -109,7 +125,9 @@  discard block
 block discarded – undo
109 125
 
110 126
 	private function getBetween($string, $start, $end) {
111 127
 		$open = strpos($string, $start);
112
-		if ($open === false) return false;
128
+		if ($open === false) {
129
+			return false;
130
+		}
113 131
 		$close = strpos($string, $end, $open);
114 132
 		return substr($string, $open+1, $close-$open-1);
115 133
 	}
Please login to merge, or discard this patch.