Completed
Push — master ( 04a4d1...1bb4b5 )
by Tom
01:56
created
src/SheetLoader.php 1 patch
Braces   +25 added lines, -9 removed lines patch added patch discarded remove patch
@@ -30,7 +30,9 @@  discard block
 block discarded – undo
30 30
 		$rules = $this->cache->load($key, filemtime($file));
31 31
 		if ($rules) {
32 32
 			foreach ($rules['import'] as $file) {
33
-				if (!$this->cache->load($this->getCacheKey($file), filemtime($file))) return false;
33
+				if (!$this->cache->load($this->getCacheKey($file), filemtime($file))) {
34
+					return false;
35
+				}
34 36
 			}
35 37
 		}
36 38
 		return $rules;
@@ -48,7 +50,9 @@  discard block
 block discarded – undo
48 50
 		if (is_file($file)) {
49 51
 			$key = $this->getCacheKey($file);
50 52
 			$existing = $this->cache->load($key, filemtime($file));
51
-			if (isset($existing['import']) && empty($imports)) $imports = $existing['import'];
53
+			if (isset($existing['import']) && empty($imports)) {
54
+				$imports = $existing['import'];
55
+			}
52 56
 			$this->cache->write($key, ['rules' => $rules, 'import' => $imports]);
53 57
 		}
54 58
 		return $rules;
@@ -60,10 +64,14 @@  discard block
 block discarded – undo
60 64
 		usort($rules, [$this, 'sortRules']);
61 65
 
62 66
 		foreach ($rules as $rule) {
63
-			if ($rule->shouldRun($this->time)) $this->executeTssRule($rule, $template, $config);
67
+			if ($rule->shouldRun($this->time)) {
68
+				$this->executeTssRule($rule, $template, $config);
69
+			}
64 70
 		}
65 71
 
66
-		if (is_file($this->tss)) $this->write($this->tss, $rules, $this->import);
72
+		if (is_file($this->tss)) {
73
+			$this->write($this->tss, $rules, $this->import);
74
+		}
67 75
 	}
68 76
 
69 77
 	//Load the TSS
@@ -72,8 +80,11 @@  discard block
 block discarded – undo
72 80
     		//$rules = $this->cache->load($tss);
73 81
     		$rules = $this->getRulesFromCache($tss)['rules'];
74 82
 			$this->filePath->addPath(dirname(realpath($tss)));
75
-			if (empty($rules)) $tss = file_get_contents($tss);
76
-			else return $rules;
83
+			if (empty($rules)) {
84
+				$tss = file_get_contents($tss);
85
+			} else {
86
+				return $rules;
87
+			}
77 88
     	}
78 89
 		return (new Parser\Sheet($tss, $cssToXpath, $valueParser, $this->filePath, $this))->parse();
79 90
 	}
@@ -91,10 +102,15 @@  discard block
 block discarded – undo
91 102
 
92 103
 	private function sortRules($a, $b) {
93 104
 		//If they have the same depth, compare on index
94
-		if ($a->query === $b->query) return $this->sortPseudo($a, $b);
105
+		if ($a->query === $b->query) {
106
+			return $this->sortPseudo($a, $b);
107
+		}
95 108
 
96
-		if ($a->depth === $b->depth) $property = 'index';
97
-		else $property = 'depth';
109
+		if ($a->depth === $b->depth) {
110
+			$property = 'index';
111
+		} else {
112
+			$property = 'depth';
113
+		}
98 114
 
99 115
 		return ($a->$property < $b->$property) ? -1 : 1;
100 116
 	}
Please login to merge, or discard this patch.
src/Builder.php 1 patch
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
@@ -62,7 +64,9 @@  discard block
 block discarded – undo
62 64
 		$valueParser = new Parser\Value($functionSet);
63 65
 		$this->config = new Config($functionSet, $valueParser, $elementData, new Hook\Formatter(), new Parser\CssToXpath($functionSet, $template->getPrefix(), md5($this->tss)), $this->filePath, $headers);
64 66
 
65
-		foreach ($this->modules as $module) $module->load($this->config);
67
+		foreach ($this->modules as $module) {
68
+			$module->load($this->config);
69
+		}
66 70
 
67 71
 		$tssCache->processRules($template, $this->config);
68 72
 
@@ -83,7 +87,9 @@  discard block
 block discarded – undo
83 87
 	//Load a template, firstly check if it's a file or a valid string
84 88
 	private function loadTemplate() {
85 89
         $result = ['body' => $this->template, 'headers' => []];
86
-		if (strpos($this->template, "\n") === false && is_file($this->template)) $result = $this->loadTemplateFromFile($this->template);
90
+		if (strpos($this->template, "\n") === false && is_file($this->template)) {
91
+			$result = $this->loadTemplateFromFile($this->template);
92
+		}
87 93
 		return $result;
88 94
 	}
89 95
 
@@ -102,6 +108,8 @@  discard block
 block discarded – undo
102 108
 
103 109
 	public function __destruct() {
104 110
 		//Required hack as DomXPath can only register static functions clear the statically stored instance to avoid memory leaks
105
-		if (isset($this->config)) $this->config->getCssToXpath()->cleanup();
111
+		if (isset($this->config)) {
112
+			$this->config->getCssToXpath()->cleanup();
113
+		}
106 114
 	}
107 115
 }
Please login to merge, or discard this patch.
src/Parser/Sheet.php 1 patch
Braces   +14 added lines, -5 removed lines patch added patch discarded remove patch
@@ -24,7 +24,9 @@  discard block
 block discarded – undo
24 24
 	}
25 25
 
26 26
 	public function parse($indexStart = 0) {
27
-		if (!empty($this->rules)) return $this->rules['rules'];
27
+		if (!empty($this->rules)) {
28
+			return $this->rules['rules'];
29
+		}
28 30
 		$rules = $this->parseTokens($indexStart);
29 31
 		$this->checkError($rules);
30 32
 		return $rules;
@@ -35,8 +37,9 @@  discard block
 block discarded – undo
35 37
 		foreach (new TokenFilterIterator($this->tss, [Tokenizer::WHITESPACE]) as $token) {
36 38
 			if ($processing = $this->processingInstructions($token, count($this->rules)+$indexStart)) {
37 39
 				$this->rules = array_merge($this->rules, $processing);
40
+			} else if ($token['type'] !== Tokenizer::NEW_LINE) {
41
+				$this->addRules($token, $indexStart++);
38 42
 			}
39
-			else if ($token['type'] !== Tokenizer::NEW_LINE) $this->addRules($token, $indexStart++);
40 43
 		}
41 44
 
42 45
 		return $this->rules;
@@ -46,13 +49,17 @@  discard block
 block discarded – undo
46 49
 		$selector = $this->tss->from($token['type'], true)->to(Tokenizer::OPEN_BRACE);
47 50
 
48 51
 		$this->tss->skip(count($selector));
49
-		if (count($selector) === 0) return;
52
+		if (count($selector) === 0) {
53
+			return;
54
+		}
50 55
 		$newRules = $this->cssToRules($selector, count($this->rules)+$indexStart, $this->getProperties($this->tss->current()['value']), $token['line']);
51 56
 		$this->rules = $this->writeRule($this->rules, $newRules);
52 57
 	}
53 58
 
54 59
 	private function checkError($rules) {
55
-		if (empty($rules) && count($this->tss) > 0) throw new \Exception('No TSS rules parsed');
60
+		if (empty($rules) && count($this->tss) > 0) {
61
+			throw new \Exception('No TSS rules parsed');
62
+		}
56 63
 	}
57 64
 
58 65
 	private function CssToRules($selector, $index, $properties, $line) {
@@ -79,7 +86,9 @@  discard block
 block discarded – undo
79 86
 	}
80 87
 
81 88
 	private function processingInstructions($token, $indexStart) {
82
-		if ($token['type'] !== Tokenizer::AT_SIGN) return false;
89
+		if ($token['type'] !== Tokenizer::AT_SIGN) {
90
+			return false;
91
+		}
83 92
 		$tokens = $this->tss->from(Tokenizer::AT_SIGN, false)->to(Tokenizer::SEMI_COLON, false);
84 93
 		$funcName = $tokens->from(Tokenizer::NAME, true)->read();
85 94
 		$args = $this->valueParser->parseTokens($tokens->from(Tokenizer::NAME));
Please login to merge, or discard this patch.