Completed
Push — master ( be6b9d...0e6890 )
by Tom
03:08
created
src/Property/Repeat.php 3 patches
Doc Comments   +6 added lines patch added patch discarded remove patch
@@ -8,6 +8,9 @@  discard block
 block discarded – undo
8 8
 class Repeat implements \Transphporm\Property {
9 9
 	private $data;
10 10
 
11
+	/**
12
+	 * @param \Transphporm\Hook\DataFunction $data
13
+	 */
11 14
 	public function __construct($data) {
12 15
 		$this->data = $data;
13 16
 	}
@@ -35,6 +38,9 @@  discard block
 block discarded – undo
35 38
 		return false;
36 39
 	}
37 40
 
41
+	/**
42
+	 * @param \Transphporm\Hook\Rule $rule
43
+	 */
38 44
 	private function createHook($newRules, $rule) {
39 45
 		$hook = new \Transphporm\Hook\Rule($newRules, $rule->getPseudoMatcher(), $this->data);
40 46
 		foreach ($rule->getProperties() as $name => $property) $hook->registerProperty($name, $property);
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@
 block discarded – undo
12 12
 		$this->data = $data;
13 13
 	}
14 14
 
15
-	public function run($value, \DomElement $element, \Transphporm\Hook\Rule $rule)  {
15
+	public function run($value, \DomElement $element, \Transphporm\Hook\Rule $rule) {
16 16
 		if ($element->getAttribute('transphporm') === 'added') return $element->parentNode->removeChild($element);
17 17
 
18 18
 		foreach ($value as $key => $iteration) {
Please login to merge, or discard this patch.
Braces   +6 added lines, -2 removed lines patch added patch discarded remove patch
@@ -13,7 +13,9 @@  discard block
 block discarded – undo
13 13
 	}
14 14
 
15 15
 	public function run($value, \DomElement $element, \Transphporm\Hook\Rule $rule)  {
16
-		if ($element->getAttribute('transphporm') === 'added') return $element->parentNode->removeChild($element);
16
+		if ($element->getAttribute('transphporm') === 'added') {
17
+			return $element->parentNode->removeChild($element);
18
+		}
17 19
 
18 20
 		foreach ($value as $key => $iteration) {
19 21
 			$clone = $element->cloneNode(true);
@@ -37,7 +39,9 @@  discard block
 block discarded – undo
37 39
 
38 40
 	private function createHook($newRules, $rule) {
39 41
 		$hook = new \Transphporm\Hook\Rule($newRules, $rule->getPseudoMatcher(), $this->data);
40
-		foreach ($rule->getProperties() as $name => $property) $hook->registerProperty($name, $property);
42
+		foreach ($rule->getProperties() as $name => $property) {
43
+			$hook->registerProperty($name, $property);
44
+		}
41 45
 		return $hook;
42 46
 	}
43 47
 }
44 48
\ No newline at end of file
Please login to merge, or discard this patch.
src/Hook/Rule.php 1 patch
Braces   +29 added lines, -14 removed lines patch added patch discarded remove patch
@@ -20,11 +20,15 @@  discard block
 block discarded – undo
20 20
 
21 21
 	public function run(\DomElement $element) {	
22 22
 		//Don't run if there's a pseudo element like nth-child() and this element doesn't match it
23
-		if (!$this->pseudoMatcher->matches($element)) return;
23
+		if (!$this->pseudoMatcher->matches($element)) {
24
+			return;
25
+		}
24 26
 
25 27
 		foreach ($this->rules as $name => $value) {
26 28
 			$result = $this->callProperty($name, $element, $this->parseValue(trim($value), $element));
27
-			if ($result === false) break;
29
+			if ($result === false) {
30
+				break;
31
+			}
28 32
 		}
29 33
 	}
30 34
 
@@ -45,7 +49,9 @@  discard block
 block discarded – undo
45 49
 	}
46 50
 
47 51
 	private function callProperty($name, $element, $value) {
48
-		if (isset($this->properties[$name])) return $this->properties[$name]->run($value, $element, $this);
52
+		if (isset($this->properties[$name])) {
53
+			return $this->properties[$name]->run($value, $element, $this);
54
+		}
49 55
 		return false;
50 56
 	}
51 57
 
@@ -53,8 +59,9 @@  discard block
 block discarded – undo
53 59
 		$pos = $start+1;
54 60
 		$end = 0;
55 61
 		while ($end = strpos($string, $char, $pos)) {
56
-			if ($string[$end-1] === $escape) $pos = $end+1;
57
-			else {
62
+			if ($string[$end-1] === $escape) {
63
+				$pos = $end+1;
64
+			} else {
58 65
 				break;
59 66
 			}
60 67
 		}
@@ -75,14 +82,17 @@  discard block
 block discarded – undo
75 82
 
76 83
 			//Count the number of fresh opening ( before $close
77 84
 			$cPos = $open+1;
78
-			while (($cPos = strpos($function, '(', $cPos+1)) !== false && $cPos < $close) $close = strpos($function, ')', $close+1);
85
+			while (($cPos = strpos($function, '(', $cPos+1)) !== false && $cPos < $close) {
86
+				$close = strpos($function, ')', $close+1);
87
+			}
79 88
 
80 89
 			$name = substr($function, 0, $open);
81 90
 
82 91
 			$params = substr($function, $open+1, $close-$open-1);
83 92
 			return ['name' => $name, 'params' => $params, 'endPoint' => $close];
93
+		} else {
94
+			return ['name' => null, 'params' => $function, 'endPoint' => strlen($function)];
84 95
 		}
85
-		else return ['name' => null, 'params' => $function, 'endPoint' => strlen($function)];
86 96
 		
87 97
 	}
88 98
 
@@ -91,23 +101,26 @@  discard block
 block discarded – undo
91 101
 		if ($function && in_array($function[0], ['\'', '"'])) {
92 102
 			$finalPos = $this->findMatchingPos($function, $function[0]);
93 103
 			$result[] = $this->extractQuotedString($function[0], $function);
94
-		}
95
-		else {
104
+		} else {
96 105
 			$func = $this->parseFunction($function);
97 106
 			$finalPos = $func['endPoint'];			
98 107
 
99 108
 			if (($data = $this->callFunc($func['name'], $func['params'], $element)) !== false) {
100 109
 				$result = $this->appendToArray($result, $data);
101
-			} 
102
-			else $result[] = trim($function);
110
+			} else {
111
+				$result[] = trim($function);
112
+			}
103 113
 		}
104 114
 		$remaining = trim(substr($function, $finalPos+1));
105 115
 		return $this->parseNextValue($remaining, $result, $element);
106 116
 	}
107 117
 
108 118
 	private function appendToArray($array, $value) {
109
-		if (is_array($value)) $array += $value;
110
-		else $array[] = $value;
119
+		if (is_array($value)) {
120
+			$array += $value;
121
+		} else {
122
+			$array[] = $value;
123
+		}
111 124
 		return $array;
112 125
 	}
113 126
 
@@ -119,7 +132,9 @@  discard block
 block discarded – undo
119 132
 	}
120 133
 
121 134
 	private function parseNextValue($remaining, $result, $element) {
122
-		if (strlen($remaining) > 0 && $remaining[0] == ',') $result = array_merge($result, $this->parseValue(trim(substr($remaining, 1)), $element));
135
+		if (strlen($remaining) > 0 && $remaining[0] == ',') {
136
+			$result = array_merge($result, $this->parseValue(trim(substr($remaining, 1)), $element));
137
+		}
123 138
 		return $result;
124 139
 	}
125 140
 
Please login to merge, or discard this patch.
src/Builder.php 1 patch
Braces   +25 added lines, -10 removed lines patch added patch discarded remove patch
@@ -43,7 +43,9 @@  discard block
 block discarded – undo
43 43
 
44 44
 		//Allow $time to be set via arguments to spoof time passage during tests
45 45
 		foreach ($this->getRules($template) as $rule) {
46
-			if ($rule->shouldRun($this->time)) $this->executeTssRule($rule, $template, $data);			
46
+			if ($rule->shouldRun($this->time)) {
47
+				$this->executeTssRule($rule, $template, $data);
48
+			}
47 49
 		}
48 50
 		
49 51
 		$result = ['body' => $template->output($document), 'headers' => array_merge($cachedOutput['headers'], $headers)];
@@ -63,7 +65,9 @@  discard block
 block discarded – undo
63 65
 	private function executeTssRule($rule, $template, $data) {
64 66
 		$rule->touch();
65 67
 		$hook = new Hook\Rule($rule->properties, new Hook\PseudoMatcher($rule->pseudo, $data), $data);
66
-		foreach ($this->registeredProperties as $name => $property) $hook->registerProperty($name, $property);
68
+		foreach ($this->registeredProperties as $name => $property) {
69
+			$hook->registerProperty($name, $property);
70
+		}
67 71
 		$template->addHook($rule->query, $hook);
68 72
 	}
69 73
 
@@ -72,8 +76,9 @@  discard block
 block discarded – undo
72 76
 		if (trim($this->template)[0] !== '<') {			
73 77
 			$xml = $this->cache->load($this->template, filemtime($this->template));
74 78
 			return $xml ? $xml : ['body' => file_get_contents($this->template), 'headers' => []];
79
+		} else {
80
+			return ['body' => $this->template, 'headers' => []];
75 81
 		}
76
-		else return ['body' => $this->template, 'headers' => []];	
77 82
 	}
78 83
 
79 84
 	//Load the TSS rules either from a file or as a string
@@ -87,10 +92,14 @@  discard block
 block discarded – undo
87 92
 			$key = $this->tss . $template->getPrefix() . $this->baseDir;
88 93
 			//Try to load the cached rules, if not set in the cache (or expired) parse the supplied sheet
89 94
 			$rules = $this->cache->load($key, filemtime($this->tss));
90
-			if (!$rules) return $this->cache->write($key, (new Sheet(file_get_contents($this->tss), $this->baseDir, $template->getPrefix()))->parse());
91
-			else return $rules;
95
+			if (!$rules) {
96
+				return $this->cache->write($key, (new Sheet(file_get_contents($this->tss), $this->baseDir, $template->getPrefix()))->parse());
97
+			} else {
98
+				return $rules;
99
+			}
100
+		} else {
101
+			return (new Sheet($this->tss, $this->baseDir, $template->getPrefix()))->parse();
92 102
 		}
93
-		else return (new Sheet($this->tss, $this->baseDir, $template->getPrefix()))->parse();
94 103
 	}
95 104
 
96 105
 	private function getContentProperty($data, $locale, &$headers) {
@@ -99,7 +108,9 @@  discard block
 block discarded – undo
99 108
 		$formatter->register(new Formatter\Date($locale));
100 109
 		$formatter->register(new Formatter\StringFormatter());
101 110
 		
102
-		foreach ($this->formatters as $format) $formatter->register($format);
111
+		foreach ($this->formatters as $format) {
112
+			$formatter->register($format);
113
+		}
103 114
 
104 115
 		$basicProperties = new Property\Content($data, $headers, $formatter);
105 116
 
@@ -111,9 +122,13 @@  discard block
 block discarded – undo
111 122
 	}
112 123
 
113 124
 	private function getLocale() {
114
-		if (is_array($this->locale)) return $this->locale;
115
-		else if (strlen($this->locale) > 0) return json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'Formatter' . DIRECTORY_SEPARATOR . 'Locale' . DIRECTORY_SEPARATOR . $this->locale . '.json'), true);
116
-		else return json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'Formatter' . DIRECTORY_SEPARATOR . 'Locale' . DIRECTORY_SEPARATOR . 'enGB.json'), true);
125
+		if (is_array($this->locale)) {
126
+			return $this->locale;
127
+		} else if (strlen($this->locale) > 0) {
128
+			return json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'Formatter' . DIRECTORY_SEPARATOR . 'Locale' . DIRECTORY_SEPARATOR . $this->locale . '.json'), true);
129
+		} else {
130
+			return json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'Formatter' . DIRECTORY_SEPARATOR . 'Locale' . DIRECTORY_SEPARATOR . 'enGB.json'), true);
131
+		}
117 132
 	}
118 133
 
119 134
 	public function registerProperty($name, Property $property) {
Please login to merge, or discard this patch.
src/Property/Display.php 1 patch
Braces   +5 added lines, -2 removed lines patch added patch discarded remove patch
@@ -7,7 +7,10 @@
 block discarded – undo
7 7
 namespace Transphporm\Property;
8 8
 class Display implements \Transphporm\Property {
9 9
 	public function run($value, \DomElement $element, \Transphporm\Hook\Rule $rule) {
10
-		if (strtolower($value[0]) === 'none') $element->setAttribute('transphporm', 'remove');
11
-		else $element->setAttribute('transphporm', 'show');
10
+		if (strtolower($value[0]) === 'none') {
11
+			$element->setAttribute('transphporm', 'remove');
12
+		} else {
13
+			$element->setAttribute('transphporm', 'show');
14
+		}
12 15
 	}
13 16
 }
14 17
\ No newline at end of file
Please login to merge, or discard this patch.
src/Property/Bind.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@
 block discarded – undo
12 12
 		$this->data = $data;
13 13
 	}
14 14
 
15
-	public function run($value, \DomElement $element, \Transphporm\Hook\Rule $rule)  {
15
+	public function run($value, \DomElement $element, \Transphporm\Hook\Rule $rule) {
16 16
 		$this->data->bind($element, $value);
17 17
 	}
18 18
 }
19 19
\ No newline at end of file
Please login to merge, or discard this patch.
src/Property/Content.php 1 patch
Braces   +8 added lines, -3 removed lines patch added patch discarded remove patch
@@ -22,8 +22,11 @@  discard block
 block discarded – undo
22 22
 			//Remove the current contents
23 23
 			$this->removeAllChildren($element);
24 24
 			//Now make a text node
25
-			if ($this->getContentMode($rule->getRules()) === 'replace') $this->replaceContent($element, $value);
26
-			else $this->appendContent($element, $value);
25
+			if ($this->getContentMode($rule->getRules()) === 'replace') {
26
+				$this->replaceContent($element, $value);
27
+			} else {
28
+				$this->appendContent($element, $value);
29
+			}
27 30
 		}
28 31
 	}
29 32
 
@@ -88,6 +91,8 @@  discard block
 block discarded – undo
88 91
 	}
89 92
 
90 93
 	private function removeAllChildren($element) {
91
-		while ($element->hasChildNodes()) $element->removeChild($element->firstChild);
94
+		while ($element->hasChildNodes()) {
95
+			$element->removeChild($element->firstChild);
96
+		}
92 97
 	}
93 98
 }
94 99
\ No newline at end of file
Please login to merge, or discard this patch.