Completed
Push — master ( 022040...908f5a )
by Tom
04:25 queued 02:39
created
src/TSSValidator.php 2 patches
Braces   +12 added lines, -6 removed lines patch added patch discarded remove patch
@@ -13,14 +13,17 @@  discard block
 block discarded – undo
13 13
         $this->error = null;
14 14
         $tokens = $this->tokenize($tss);
15 15
 
16
-        foreach ($tokens as $token)
17
-            if (!$this->validateRule($token)) return false;
16
+        foreach ($tokens as $token) {
17
+                    if (!$this->validateRule($token)) return false;
18
+        }
18 19
 
19 20
         return true;
20 21
     }
21 22
 
22 23
     private function validateRule($token) {
23
-        if ($token['type'] !== Tokenizer::OPEN_BRACE) return true;
24
+        if ($token['type'] !== Tokenizer::OPEN_BRACE) {
25
+        	return true;
26
+        }
24 27
 
25 28
         return $this->checkBraces($token) && $this->checkSemicolons($token)
26 29
             && $this->checkParenthesis($token);
@@ -33,8 +36,9 @@  discard block
 block discarded – undo
33 36
     private function checkSemicolons($braceToken) {
34 37
         $splitTokens = $braceToken['value']->splitOnToken(Tokenizer::COLON);
35 38
         array_shift($splitTokens); array_pop($splitTokens);
36
-        foreach ($splitTokens as $tokens)
37
-            if (!in_array(Tokenizer::SEMI_COLON, array_column(iterator_to_array($tokens), 'type'))) return false;
39
+        foreach ($splitTokens as $tokens) {
40
+                    if (!in_array(Tokenizer::SEMI_COLON, array_column(iterator_to_array($tokens), 'type'))) return false;
41
+        }
38 42
 
39 43
         return true;
40 44
     }
@@ -44,7 +48,9 @@  discard block
 block discarded – undo
44 48
     }
45 49
 
46 50
     private function tokenize($tss) {
47
-        if (is_file($tss)) $tss = file_get_contents($tss);
51
+        if (is_file($tss)) {
52
+        	$tss = file_get_contents($tss);
53
+        }
48 54
         return (new Parser\Tokenizer($tss))->getTokens();
49 55
     }
50 56
 }
Please login to merge, or discard this patch.
Indentation   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -7,44 +7,44 @@
 block discarded – undo
7 7
 namespace Transphporm;
8 8
 use Transphporm\Parser\Tokenizer;
9 9
 class TSSValidator {
10
-    private $error;
10
+	private $error;
11 11
 
12
-    public function validate($tss) {
13
-        $this->error = null;
14
-        $tokens = $this->tokenize($tss);
12
+	public function validate($tss) {
13
+		$this->error = null;
14
+		$tokens = $this->tokenize($tss);
15 15
 
16
-        foreach ($tokens as $token)
17
-            if (!$this->validateRule($token)) return false;
16
+		foreach ($tokens as $token)
17
+			if (!$this->validateRule($token)) return false;
18 18
 
19
-        return true;
20
-    }
19
+		return true;
20
+	}
21 21
 
22
-    private function validateRule($token) {
23
-        if ($token['type'] !== Tokenizer::OPEN_BRACE) return true;
22
+	private function validateRule($token) {
23
+		if ($token['type'] !== Tokenizer::OPEN_BRACE) return true;
24 24
 
25
-        return $this->checkBraces($token) && $this->checkSemicolons($token)
26
-            && $this->checkParenthesis($token);
27
-    }
25
+		return $this->checkBraces($token) && $this->checkSemicolons($token)
26
+			&& $this->checkParenthesis($token);
27
+	}
28 28
 
29
-    private function checkBraces($token) {
30
-        return strpos($token['string'], '{') === false;
31
-    }
29
+	private function checkBraces($token) {
30
+		return strpos($token['string'], '{') === false;
31
+	}
32 32
 
33
-    private function checkSemicolons($braceToken) {
34
-        $splitTokens = $braceToken['value']->splitOnToken(Tokenizer::COLON);
35
-        array_shift($splitTokens); array_pop($splitTokens);
36
-        foreach ($splitTokens as $tokens)
37
-            if (!in_array(Tokenizer::SEMI_COLON, array_column(iterator_to_array($tokens), 'type'))) return false;
33
+	private function checkSemicolons($braceToken) {
34
+		$splitTokens = $braceToken['value']->splitOnToken(Tokenizer::COLON);
35
+		array_shift($splitTokens); array_pop($splitTokens);
36
+		foreach ($splitTokens as $tokens)
37
+			if (!in_array(Tokenizer::SEMI_COLON, array_column(iterator_to_array($tokens), 'type'))) return false;
38 38
 
39
-        return true;
40
-    }
39
+		return true;
40
+	}
41 41
 
42
-    private function checkParenthesis($token) {
43
-        return substr_count($token['string'], '(') === substr_count($token['string'], ')');
44
-    }
42
+	private function checkParenthesis($token) {
43
+		return substr_count($token['string'], '(') === substr_count($token['string'], ')');
44
+	}
45 45
 
46
-    private function tokenize($tss) {
47
-        if (is_file($tss)) $tss = file_get_contents($tss);
48
-        return (new Parser\Tokenizer($tss))->getTokens();
49
-    }
46
+	private function tokenize($tss) {
47
+		if (is_file($tss)) $tss = file_get_contents($tss);
48
+		return (new Parser\Tokenizer($tss))->getTokens();
49
+	}
50 50
 }
Please login to merge, or discard this patch.
src/FilePath.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -19,15 +19,15 @@
 block discarded – undo
19 19
 
20 20
 	public function getFilePath($filePath) {
21 21
 		if (is_file($filePath)) return $filePath;
22
-		else if (is_file($this->baseDir . DIRECTORY_SEPARATOR . $filePath)) return $this->baseDir . DIRECTORY_SEPARATOR . $filePath;
22
+		else if (is_file($this->baseDir.DIRECTORY_SEPARATOR.$filePath)) return $this->baseDir.DIRECTORY_SEPARATOR.$filePath;
23 23
 		else return $this->loadFromPaths($filePath);
24 24
 	}
25 25
 
26 26
 	private function loadFromPaths($filePath) {
27 27
 		foreach ($this->paths as $path) {
28
-			if (is_file($path . DIRECTORY_SEPARATOR . $filePath)) return $path . DIRECTORY_SEPARATOR . $filePath;
28
+			if (is_file($path.DIRECTORY_SEPARATOR.$filePath)) return $path.DIRECTORY_SEPARATOR.$filePath;
29 29
 		}
30 30
 
31
-		throw new \Exception('File ' . $filePath . ' not found in paths (' . implode(', ', $this->paths) . ')');
31
+		throw new \Exception('File '.$filePath.' not found in paths ('.implode(', ', $this->paths).')');
32 32
 	}
33 33
 }
Please login to merge, or discard this patch.
Braces   +10 added lines, -4 removed lines patch added patch discarded remove patch
@@ -18,14 +18,20 @@
 block discarded – undo
18 18
 	}
19 19
 
20 20
 	public function getFilePath($filePath) {
21
-		if (is_file($filePath)) return $filePath;
22
-		else if (is_file($this->baseDir . DIRECTORY_SEPARATOR . $filePath)) return $this->baseDir . DIRECTORY_SEPARATOR . $filePath;
23
-		else return $this->loadFromPaths($filePath);
21
+		if (is_file($filePath)) {
22
+			return $filePath;
23
+		} else if (is_file($this->baseDir . DIRECTORY_SEPARATOR . $filePath)) {
24
+			return $this->baseDir . DIRECTORY_SEPARATOR . $filePath;
25
+		} else {
26
+			return $this->loadFromPaths($filePath);
27
+		}
24 28
 	}
25 29
 
26 30
 	private function loadFromPaths($filePath) {
27 31
 		foreach ($this->paths as $path) {
28
-			if (is_file($path . DIRECTORY_SEPARATOR . $filePath)) return $path . DIRECTORY_SEPARATOR . $filePath;
32
+			if (is_file($path . DIRECTORY_SEPARATOR . $filePath)) {
33
+				return $path . DIRECTORY_SEPARATOR . $filePath;
34
+			}
29 35
 		}
30 36
 
31 37
 		throw new \Exception('File ' . $filePath . ' not found in paths (' . implode(', ', $this->paths) . ')');
Please login to merge, or discard this patch.
src/Template.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
 			$this->save = function($content = null) {
39 39
 				return $this->document->saveHtml($content);
40 40
 			};
41
-			$this->document->loadHtml('<' . '?xml encoding="UTF-8">' . $doc,  LIBXML_HTML_NODEFDTD | LIBXML_HTML_NOIMPLIED);
41
+			$this->document->loadHtml('<'.'?xml encoding="UTF-8">'.$doc, LIBXML_HTML_NODEFDTD | LIBXML_HTML_NOIMPLIED);
42 42
 
43 43
 		}
44 44
 		else {
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
 		if ($document) return $this->document;
90 90
 
91 91
 		//Print the doctype... saveHtml inexplicably does not support $doc->doctype as an argument
92
-		$output = ($this->document->doctype) ? $this->document->saveXml($this->document->doctype) . "\n" : '';
92
+		$output = ($this->document->doctype) ? $this->document->saveXml($this->document->doctype)."\n" : '';
93 93
 
94 94
 		if ($this->document->documentElement->tagName !== 'template') $output .= call_user_func($this->save, $this->document->documentElement);
95 95
 		else $output = $this->printDocument();
Please login to merge, or discard this patch.
Braces   +15 added lines, -7 removed lines patch added patch discarded remove patch
@@ -40,8 +40,7 @@  discard block
 block discarded – undo
40 40
 			};
41 41
 			$this->document->loadHtml('<' . '?xml encoding="UTF-8">' . $doc,  LIBXML_HTML_NODEFDTD | LIBXML_HTML_NOIMPLIED);
42 42
 
43
-		}
44
-		else {
43
+		} else {
45 44
 			$this->document->loadXml($doc);
46 45
 			//XML was loaded, save as XML.
47 46
 			$this->save = function($content = null) {
@@ -66,7 +65,9 @@  discard block
 block discarded – undo
66 65
 	/** Loops through all assigned hooks, runs the Xpath query and calls the hook */
67 66
 	private function processHooks() {
68 67
 		foreach ($this->hooks as list($query, $hook)) {
69
-			foreach ($this->xpath->query($query) as $element) $hook->run($element);
68
+			foreach ($this->xpath->query($query) as $element) {
69
+				$hook->run($element);
70
+			}
70 71
 		}
71 72
 		$this->hooks = [];
72 73
 	}
@@ -74,7 +75,9 @@  discard block
 block discarded – undo
74 75
 	/** Prints out the current DomDocument as HTML */
75 76
 	private function printDocument() {
76 77
 		$output = '';
77
-		foreach ($this->document->documentElement->childNodes as $node) $output .= call_user_func($this->save, $node);
78
+		foreach ($this->document->documentElement->childNodes as $node) {
79
+			$output .= call_user_func($this->save, $node);
80
+		}
78 81
 		return $output;
79 82
 	}
80 83
 
@@ -86,13 +89,18 @@  discard block
 block discarded – undo
86 89
 		//Generate the document by taking only the childnodes of the template, ignoring the <template> and </template> tags
87 90
 		//TODO: Is there a faster way of doing this without string manipulation on the output or this loop through childnodes?
88 91
 		 //Either return a whole DomDocument or return the output HTML
89
-		if ($document) return $this->document;
92
+		if ($document) {
93
+			return $this->document;
94
+		}
90 95
 
91 96
 		//Print the doctype... saveHtml inexplicably does not support $doc->doctype as an argument
92 97
 		$output = ($this->document->doctype) ? $this->document->saveXml($this->document->doctype) . "\n" : '';
93 98
 
94
-		if ($this->document->documentElement->tagName !== 'template') $output .= call_user_func($this->save, $this->document->documentElement);
95
-		else $output = $this->printDocument();
99
+		if ($this->document->documentElement->tagName !== 'template') {
100
+			$output .= call_user_func($this->save, $this->document->documentElement);
101
+		} else {
102
+			$output = $this->printDocument();
103
+		}
96 104
 
97 105
 		//repair empty tags. Browsers break on <script /> and <div /> so can't avoid LIBXML_NOEMPTYTAG but they also break on <base></base> so repair them
98 106
 		$output = str_replace(['></img>', '></br>', '></meta>', '></base>', '></link>', '></hr>', '></input>'], ' />', $output);
Please login to merge, or discard this patch.
src/TSSFunction/Json.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -17,13 +17,13 @@
 block discarded – undo
17 17
 
18 18
 		if ($this->isJsonFile($json)) {
19 19
 			$path = $this->filePath->getFilePath($json);
20
-			if (!file_exists($path)) throw new \Exception('File does not exist at: ' . $path);
20
+			if (!file_exists($path)) throw new \Exception('File does not exist at: '.$path);
21 21
 			$json = file_get_contents($path);
22 22
 		}
23 23
 
24 24
 		$map = json_decode($json, true);
25 25
 
26
-		if (!is_array($map)) throw new \Exception('Could not decode json: ' . json_last_error_msg());
26
+		if (!is_array($map)) throw new \Exception('Could not decode json: '.json_last_error_msg());
27 27
 
28 28
 		return $map;
29 29
 	}
Please login to merge, or discard this patch.
Braces   +6 added lines, -2 removed lines patch added patch discarded remove patch
@@ -17,13 +17,17 @@
 block discarded – undo
17 17
 
18 18
 		if ($this->isJsonFile($json)) {
19 19
 			$path = $this->filePath->getFilePath($json);
20
-			if (!file_exists($path)) throw new \Exception('File does not exist at: ' . $path);
20
+			if (!file_exists($path)) {
21
+				throw new \Exception('File does not exist at: ' . $path);
22
+			}
21 23
 			$json = file_get_contents($path);
22 24
 		}
23 25
 
24 26
 		$map = json_decode($json, true);
25 27
 
26
-		if (!is_array($map)) throw new \Exception('Could not decode json: ' . json_last_error_msg());
28
+		if (!is_array($map)) {
29
+			throw new \Exception('Could not decode json: ' . json_last_error_msg());
30
+		}
27 31
 
28 32
 		return $map;
29 33
 	}
Please login to merge, or discard this patch.
src/Hook/ElementData.php 1 patch
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -25,7 +25,9 @@
 block discarded – undo
25 25
 	/** 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*/
26 26
 	public function getData(\DomElement $element = null, $type = 'data') {
27 27
 		while ($element) {
28
-			if (isset($this->elementMap[$element]) && array_key_exists($type, $this->elementMap[$element])) return $this->elementMap[$element][$type];
28
+			if (isset($this->elementMap[$element]) && array_key_exists($type, $this->elementMap[$element])) {
29
+				return $this->elementMap[$element][$type];
30
+			}
29 31
 			$element = $element->parentNode;
30 32
 		}
31 33
 		return $this->data;
Please login to merge, or discard this patch.
src/Parser/ValueResult.php 1 patch
Braces   +8 added lines, -5 removed lines patch added patch discarded remove patch
@@ -33,14 +33,17 @@
 block discarded – undo
33 33
 		];
34 34
 
35 35
 		if ($funcs[$this->mode] === 'concat' && is_numeric($newValue)
36
-			&& is_numeric($this->result[count($this->result)-1]))
37
-			$this->add($newValue);
38
-		else
39
-			$this->{$funcs[$this->mode]}($newValue);
36
+			&& is_numeric($this->result[count($this->result)-1])) {
37
+					$this->add($newValue);
38
+		} else {
39
+					$this->{$funcs[$this->mode]}($newValue);
40
+		}
40 41
 	}
41 42
 
42 43
 	public function in($value) {
43
-		if (!is_array($value)) throw new \Exception(' `in` can only be used with arrays');
44
+		if (!is_array($value)) {
45
+			throw new \Exception(' `in` can only be used with arrays');
46
+		}
44 47
 		$this->result[count($this->result)-1] = in_array($this->result[count($this->result)-1], $value);
45 48
 	}
46 49
 
Please login to merge, or discard this patch.
src/Parser/Tokenizer/Literals.php 1 patch
Braces   +7 added lines, -3 removed lines patch added patch discarded remove patch
@@ -37,9 +37,13 @@
 block discarded – undo
37 37
 	}
38 38
 
39 39
 	private function processLiterals($tokens, $name, $str) {
40
-		if (is_numeric($name)) $tokens->add(['type' => Tokenizer::NUMERIC, 'value' => $name]);
41
-		else if (method_exists($this, $name)) $this->$name($tokens);
42
-		else $tokens->add(['type' => Tokenizer::NAME, 'value' => $name, 'line' => $str->lineNo()]);
40
+		if (is_numeric($name)) {
41
+			$tokens->add(['type' => Tokenizer::NUMERIC, 'value' => $name]);
42
+		} else if (method_exists($this, $name)) {
43
+			$this->$name($tokens);
44
+		} else {
45
+			$tokens->add(['type' => Tokenizer::NAME, 'value' => $name, 'line' => $str->lineNo()]);
46
+		}
43 47
 	}
44 48
 
45 49
 	private function true($tokens) {
Please login to merge, or discard this patch.
src/FunctionSet.php 1 patch
Braces   +4 added lines, -3 removed lines patch added patch discarded remove patch
@@ -26,11 +26,12 @@
 block discarded – undo
26 26
 	private function getArgs0($name, $args) {
27 27
 		if (isset($this->functions[$name]) && !($this->functions[$name] instanceof TSSFunction\Data)) {
28 28
 			$tokens = $args[0];
29
-			if ($tokens->count() == 0) return [];
29
+			if ($tokens->count() == 0) {
30
+				return [];
31
+			}
30 32
 			$parser = new \Transphporm\Parser\Value($this);
31 33
 			return $parser->parseTokens($tokens, $this->elementData->getData($this->element));
32
-		}
33
-		else {
34
+		} else {
34 35
 			return iterator_to_array($args[0]);
35 36
 		}
36 37
 
Please login to merge, or discard this patch.
src/Builder.php 3 patches
Braces   +12 added lines, -4 removed lines patch added patch discarded remove patch
@@ -27,7 +27,9 @@  discard block
 block discarded – undo
27 27
 		$this->cache = new Cache(new \ArrayObject());
28 28
 		$this->filePath = new FilePath();
29 29
 		$modules = is_array($modules) ? $modules : $this->defaultModules;
30
-		foreach ($modules as $module) $this->loadModule(new $module);
30
+		foreach ($modules as $module) {
31
+			$this->loadModule(new $module);
32
+		}
31 33
 	}
32 34
 
33 35
 	//Allow setting the time used by Transphporm for caching. This is for testing purposes
@@ -80,7 +82,9 @@  discard block
 block discarded – undo
80 82
 		$valueParser = new Parser\Value($functionSet);
81 83
 		$this->config = new Config($functionSet, $valueParser, $elementData, new Hook\Formatter(), new Parser\CssToXpath($functionSet, $template->getPrefix(), md5($this->tss)), $this->filePath, $headers);
82 84
 
83
-		foreach ($this->modules as $module) $module->load($this->config);
85
+		foreach ($this->modules as $module) {
86
+			$module->load($this->config);
87
+		}
84 88
 		return $template;
85 89
 	}
86 90
 
@@ -94,7 +98,9 @@  discard block
 block discarded – undo
94 98
 	//Load a template, firstly check if it's a file or a valid string
95 99
 	private function loadTemplate() {
96 100
         $result = ['cache' => $this->template, 'headers' => []];
97
-		if (strpos($this->template, "\n") === false && is_file($this->template)) $result = $this->loadTemplateFromFile($this->template);
101
+		if (strpos($this->template, "\n") === false && is_file($this->template)) {
102
+			$result = $this->loadTemplateFromFile($this->template);
103
+		}
98 104
 		return $result;
99 105
 	}
100 106
 
@@ -113,6 +119,8 @@  discard block
 block discarded – undo
113 119
 
114 120
 	public function __destruct() {
115 121
 		//Required hack as DomXPath can only register static functions clear the statically stored instance to avoid memory leaks
116
-		if (isset($this->config)) $this->config->getCssToXpath()->cleanup();
122
+		if (isset($this->config)) {
123
+			$this->config->getCssToXpath()->cleanup();
124
+		}
117 125
 	}
118 126
 }
Please login to merge, or discard this patch.
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -42,9 +42,9 @@  discard block
 block discarded – undo
42 42
 	}
43 43
 
44 44
 	public function setLocale($locale) {
45
-        $format = new \Transphporm\Module\Format($locale);
46
-        $this->modules[get_class($format)] = $format;
47
-    }
45
+		$format = new \Transphporm\Module\Format($locale);
46
+		$this->modules[get_class($format)] = $format;
47
+	}
48 48
 
49 49
 	public function addPath($dir) {
50 50
 		$this->filePath->addPath($dir);
@@ -100,15 +100,15 @@  discard block
 block discarded – undo
100 100
 
101 101
 	//Load a template, firstly check if it's a file or a valid string
102 102
 	private function loadTemplate() {
103
-        $result = ['cache' => $this->template, 'headers' => []];
103
+		$result = ['cache' => $this->template, 'headers' => []];
104 104
 		if (strpos($this->template, "\n") === false && is_file($this->template)) $result = $this->loadTemplateFromFile($this->template);
105 105
 		return $result;
106 106
 	}
107 107
 
108
-    private function loadTemplateFromFile($file) {
109
-        $xml = $this->cache->load($this->cacheKey . $file, filemtime($file));
110
-        return $xml ? $xml : ['cache' => file_get_contents($file) ?: "", 'headers' => []];
111
-    }
108
+	private function loadTemplateFromFile($file) {
109
+		$xml = $this->cache->load($this->cacheKey . $file, filemtime($file));
110
+		return $xml ? $xml : ['cache' => file_get_contents($file) ?: "", 'headers' => []];
111
+	}
112 112
 
113 113
 	public function setCache(\ArrayAccess $cache) {
114 114
 		$this->cache = new Cache($cache);
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
 			   'headers' => array_merge($result['headers'], $headers),
73 73
 			   'body' => $this->doPostProcessing($template)->output($document)
74 74
 			];
75
-			$this->cache->write($tssCache->getCacheKey($data) . $this->template, $result);
75
+			$this->cache->write($tssCache->getCacheKey($data).$this->template, $result);
76 76
 		}
77 77
 		unset($result['cache'], $result['renderTime']);
78 78
 		return (object) $result;
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
 		$elementData = new \Transphporm\Hook\ElementData(new \SplObjectStorage(), $data);
83 83
 		$functionSet = new FunctionSet($elementData);
84 84
 		//To be a valid XML document it must have a root element, automatically wrap it in <template> to ensure it does
85
-		$template = new Template($this->isValidDoc($body) ? str_ireplace('<!doctype', '<!DOCTYPE', $body) : '<template>' . $body . '</template>' );
85
+		$template = new Template($this->isValidDoc($body) ? str_ireplace('<!doctype', '<!DOCTYPE', $body) : '<template>'.$body.'</template>');
86 86
 
87 87
 		$valueParser = new Parser\Value($functionSet);
88 88
 		$this->config = new Config($functionSet, $valueParser, $elementData, new Hook\Formatter(), new Parser\CssToXpath($functionSet, $template->getPrefix(), md5($this->tss)), $this->filePath, $headers);
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
106 106
 	}
107 107
 
108 108
     private function loadTemplateFromFile($file) {
109
-        $xml = $this->cache->load($this->cacheKey . $file, filemtime($file));
109
+        $xml = $this->cache->load($this->cacheKey.$file, filemtime($file));
110 110
         return $xml ? $xml : ['cache' => file_get_contents($file) ?: "", 'headers' => []];
111 111
     }
112 112
 
Please login to merge, or discard this patch.