Completed
Push — master ( 678b45...fc8189 )
by Tom
03:19
created
src/Builder.php 1 patch
Braces   +25 added lines, -10 removed lines patch added patch discarded remove patch
@@ -41,7 +41,9 @@  discard block
 block discarded – undo
41 41
 
42 42
 		//Allow $time to be set via arguments to spoof time passage during tests
43 43
 		foreach ($this->getRules($template, $valueParser) as $rule) {
44
-			if ($rule->shouldRun($this->time)) $this->executeTssRule($rule, $template, $data, $valueParser);			
44
+			if ($rule->shouldRun($this->time)) {
45
+				$this->executeTssRule($rule, $template, $data, $valueParser);
46
+			}
45 47
 		}
46 48
 		
47 49
 		$result = ['body' => $template->output($document), 'headers' => array_merge($cachedOutput['headers'], $headers)];
@@ -58,7 +60,9 @@  discard block
 block discarded – undo
58 60
 		$formatter->register(new Formatter\Date($locale));
59 61
 		$formatter->register(new Formatter\StringFormatter());
60 62
 		
61
-		foreach ($this->formatters as $format) $formatter->register($format);
63
+		foreach ($this->formatters as $format) {
64
+			$formatter->register($format);
65
+		}
62 66
 
63 67
 		$this->registerProperty('content', new Property\Content($data, $headers, $formatter));
64 68
 		$this->registerProperty('repeat', new Property\Repeat($data));
@@ -76,7 +80,9 @@  discard block
 block discarded – undo
76 80
 	private function executeTssRule($rule, $template, $data, $valueParser) {
77 81
 		$rule->touch();
78 82
 		$hook = new Hook\Rule($rule->properties, new Hook\PseudoMatcher($rule->pseudo, $data), $valueParser);
79
-		foreach ($this->registeredProperties as $name => $property) $hook->registerProperty($name, $property);
83
+		foreach ($this->registeredProperties as $name => $property) {
84
+			$hook->registerProperty($name, $property);
85
+		}
80 86
 		$template->addHook($rule->query, $hook);
81 87
 	}
82 88
 
@@ -85,8 +91,9 @@  discard block
 block discarded – undo
85 91
 		if (trim($this->template)[0] !== '<') {			
86 92
 			$xml = $this->cache->load($this->template, filemtime($this->template));
87 93
 			return $xml ? $xml : ['body' => file_get_contents($this->template), 'headers' => []];
94
+		} else {
95
+			return ['body' => $this->template, 'headers' => []];
88 96
 		}
89
-		else return ['body' => $this->template, 'headers' => []];	
90 97
 	}
91 98
 
92 99
 	//Load the TSS rules either from a file or as a string
@@ -100,10 +107,14 @@  discard block
 block discarded – undo
100 107
 			$key = $this->tss . $template->getPrefix() . $this->baseDir;
101 108
 			//Try to load the cached rules, if not set in the cache (or expired) parse the supplied sheet
102 109
 			$rules = $this->cache->load($key, filemtime($this->tss));
103
-			if (!$rules) return $this->cache->write($key, (new Sheet(file_get_contents($this->tss), $this->baseDir, $valueParser, $template->getPrefix()))->parse());
104
-			else return $rules;
110
+			if (!$rules) {
111
+				return $this->cache->write($key, (new Sheet(file_get_contents($this->tss), $this->baseDir, $valueParser, $template->getPrefix()))->parse());
112
+			} else {
113
+				return $rules;
114
+			}
115
+		} else {
116
+			return (new Sheet($this->tss, $this->baseDir, $valueParser, $template->getPrefix()))->parse();
105 117
 		}
106
-		else return (new Sheet($this->tss, $this->baseDir, $valueParser, $template->getPrefix()))->parse();
107 118
 	}
108 119
 
109 120
 	public function setCache(\ArrayAccess $cache) {
@@ -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/CssToXpath.php 1 patch
Braces   +11 added lines, -4 removed lines patch added patch discarded remove patch
@@ -39,8 +39,12 @@  discard block
 block discarded – undo
39 39
 			if (strpos($attr, $comparator) !== false) {
40 40
 				$parts = explode($comparator, $attr);
41 41
 
42
-				foreach ($parts as &$part) $part = implode('', $this->valueParser->parse($part));
43
-				if (isset($parts[1])) $parts[1] = '"' . $parts[1] . '"';
42
+				foreach ($parts as &$part) {
43
+					$part = implode('', $this->valueParser->parse($part));
44
+				}
45
+				if (isset($parts[1])) {
46
+					$parts[1] = '"' . $parts[1] . '"';
47
+				}
44 48
 				return implode($comparator, $parts);
45 49
 			}
46 50
 		}
@@ -59,8 +63,9 @@  discard block
 block discarded – undo
59 63
 				$selector = $this->createSelector();
60 64
 				$selector->type = $css[$i];
61 65
 				$selectors[] = $selector;
66
+			} else {
67
+				$selector->string .= $css[$i];
62 68
 			}
63
-			else $selector->string .= $css[$i];			
64 69
 		}
65 70
 		return $selectors;
66 71
 	}
@@ -71,7 +76,9 @@  discard block
 block discarded – undo
71 76
 		$this->depth = count($selectors);
72 77
 		$xpath = '/';
73 78
 		foreach ($selectors as $selector) {
74
-			if (isset($this->translators[$selector->type])) $xpath .= $this->translators[$selector->type]($selector->string);
79
+			if (isset($this->translators[$selector->type])) {
80
+				$xpath .= $this->translators[$selector->type]($selector->string);
81
+			}
75 82
 		}
76 83
 
77 84
 		$xpath = str_replace('/[', '/*[', $xpath);
Please login to merge, or discard this patch.
src/Hook/Rule.php 1 patch
Braces   +9 added lines, -3 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->valueParser->parse(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
 
Please login to merge, or discard this patch.
src/ValueParser.php 1 patch
Braces   +20 added lines, -11 removed lines patch added patch discarded remove patch
@@ -27,14 +27,17 @@  discard block
 block discarded – undo
27 27
 
28 28
 			//Count the number of fresh opening ( before $close
29 29
 			$cPos = $open+1;
30
-			while (($cPos = strpos($function, '(', $cPos+1)) !== false && $cPos < $close) $close = strpos($function, ')', $close+1);
30
+			while (($cPos = strpos($function, '(', $cPos+1)) !== false && $cPos < $close) {
31
+				$close = strpos($function, ')', $close+1);
32
+			}
31 33
 
32 34
 			$name = substr($function, 0, $open);
33 35
 
34 36
 			$params = substr($function, $open+1, $close-$open-1);
35 37
 			return ['name' => $name, 'params' => $params, 'endPoint' => $close];
38
+		} else {
39
+			return ['name' => null, 'params' => $function, 'endPoint' => strlen($function)];
36 40
 		}
37
-		else return ['name' => null, 'params' => $function, 'endPoint' => strlen($function)];
38 41
 		
39 42
 	}
40 43
 
@@ -43,23 +46,26 @@  discard block
 block discarded – undo
43 46
 		if ($function && in_array($function[0], ['\'', '"'])) {
44 47
 			$finalPos = $this->findMatchingPos($function, $function[0]);
45 48
 			$result[] = $this->extractQuotedString($function[0], $function);
46
-		}
47
-		else {
49
+		} else {
48 50
 			$func = $this->parseFunction($function);
49 51
 			$finalPos = $func['endPoint'];			
50 52
 
51 53
 			if (($data = $this->callFunc($func['name'], $func['params'], $element)) !== false) {
52 54
 				$result = $this->appendToArray($result, $data);
53
-			} 
54
-			else $result[] = trim($function);
55
+			} else {
56
+				$result[] = trim($function);
57
+			}
55 58
 		}
56 59
 		$remaining = trim(substr($function, $finalPos+1));
57 60
 		return $this->parseNextValue($remaining, $result, $element);
58 61
 	}
59 62
 
60 63
 	private function appendToArray($array, $value) {
61
-		if (is_array($value)) $array += $value;
62
-		else $array[] = $value;
64
+		if (is_array($value)) {
65
+			$array += $value;
66
+		} else {
67
+			$array[] = $value;
68
+		}
63 69
 		return $array;
64 70
 	}
65 71
 
@@ -71,7 +77,9 @@  discard block
 block discarded – undo
71 77
 	}
72 78
 
73 79
 	private function parseNextValue($remaining, $result, $element) {
74
-		if (strlen($remaining) > 0 && $remaining[0] == ',') $result = array_merge($result, $this->parse(trim(substr($remaining, 1)), $element));
80
+		if (strlen($remaining) > 0 && $remaining[0] == ',') {
81
+			$result = array_merge($result, $this->parse(trim(substr($remaining, 1)), $element));
82
+		}
75 83
 		return $result;
76 84
 	}
77 85
 	
@@ -79,8 +87,9 @@  discard block
 block discarded – undo
79 87
 		$pos = $start+1;
80 88
 		$end = 0;
81 89
 		while ($end = strpos($string, $char, $pos)) {
82
-			if ($string[$end-1] === $escape) $pos = $end+1;
83
-			else {
90
+			if ($string[$end-1] === $escape) {
91
+				$pos = $end+1;
92
+			} else {
84 93
 				break;
85 94
 			}
86 95
 		}
Please login to merge, or discard this patch.