Completed
Push — master ( 878197...378399 )
by Tom
07:30
created
src/SheetLoader/SheetLoader.php 4 patches
Doc Comments   +12 added lines patch added patch discarded remove patch
@@ -42,6 +42,9 @@  discard block
 block discarded – undo
42 42
 	}
43 43
 
44 44
 
45
+	/**
46
+	 * @param \Transphporm\Template $template
47
+	 */
45 48
 	public function processRules($template, \Transphporm\Config $config) {
46 49
 		$rules = $this->getRules($config->getCssToXpath(), $config->getValueParser());
47 50
 
@@ -57,11 +60,20 @@  discard block
 block discarded – undo
57 60
 	}
58 61
 
59 62
 	//Load the TSS
63
+
64
+	/**
65
+	 * @param \Transphporm\Parser\CssToXpath $cssToXpath
66
+	 * @param \Transphporm\Parser\Value $valueParser
67
+	 */
60 68
 	public function getRules($cssToXpath, $valueParser, $indexStart = 0) {
61 69
 		return $this->tss->getRules($cssToXpath, $valueParser, $this, $indexStart);
62 70
 	}
63 71
 
64 72
 	//Process a TSS rule e.g. `ul li {content: "foo"; format: bar}
73
+
74
+	/**
75
+	 * @param \Transphporm\Config $config
76
+	 */
65 77
 	private function executeTssRule($rule, $template, $config) {
66 78
 		$rule->touch();
67 79
 
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -84,6 +84,6 @@
 block discarded – undo
84 84
 
85 85
 
86 86
 	private function sortPseudo($a, $b) {
87
-		return count($a->pseudo) > count($b->pseudo)  ? 1 : -1;
87
+		return count($a->pseudo) > count($b->pseudo) ? 1 : -1;
88 88
 	}
89 89
 }
Please login to merge, or discard this patch.
Braces   +13 added lines, -5 removed lines patch added patch discarded remove patch
@@ -39,8 +39,9 @@  discard block
 block discarded – undo
39 39
 			if ($token['type'] == \Transphporm\Parser\Tokenizer::NAME && $token['value'] == 'data') {
40 40
 				$tokens->next();
41 41
 				$newTokens = array_merge($newTokens, iterator_to_array($tokens->current()['value']));
42
+			} else {
43
+				$newTokens[] = $token;
42 44
 			}
43
-			else $newTokens[] = $token;
44 45
 		}
45 46
 
46 47
 		$this->tss->setCacheKey(new \Transphporm\Parser\Tokens($newTokens));
@@ -58,7 +59,9 @@  discard block
 block discarded – undo
58 59
 		usort($rules, [$this, 'sortRules']);
59 60
 
60 61
 		foreach ($rules as $rule) {
61
-			if ($rule->shouldRun($this->time)) $this->executeTssRule($rule, $template, $config);
62
+			if ($rule->shouldRun($this->time)) {
63
+				$this->executeTssRule($rule, $template, $config);
64
+			}
62 65
 		}
63 66
 
64 67
 		//if (is_file($this->tss)) $this->write($this->tss, $rules, $this->import);
@@ -83,10 +86,15 @@  discard block
 block discarded – undo
83 86
 
84 87
 	private function sortRules($a, $b) {
85 88
 		//If they have the same depth, compare on index
86
-		if ($a->query === $b->query) return $this->sortPseudo($a, $b);
89
+		if ($a->query === $b->query) {
90
+			return $this->sortPseudo($a, $b);
91
+		}
87 92
 
88
-		if ($a->depth === $b->depth) $property = 'index';
89
-		else $property = 'depth';
93
+		if ($a->depth === $b->depth) {
94
+			$property = 'index';
95
+		} else {
96
+			$property = 'depth';
97
+		}
90 98
 
91 99
 		return ($a->$property < $b->$property) ? -1 : 1;
92 100
 	}
Please login to merge, or discard this patch.
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -7,17 +7,17 @@
 block discarded – undo
7 7
 namespace Transphporm\SheetLoader;
8 8
 //Separates out TSS file loading/caching from parsing
9 9
 class SheetLoader {
10
-    private $tss;
11
-    private $filePath;
12
-    private $time;
13
-    private $import = [];
14
-
15
-    public function __construct(\Transphporm\Cache $cache, \Transphporm\FilePath $filePath, TSSRules $tss, $time) {
16
-    	$this->cache = $cache;
17
-        $this->filePath = $filePath;
18
-        $this->tss = $tss;
19
-        $this->time = isset($time) ? $time : time();
20
-    }
10
+	private $tss;
11
+	private $filePath;
12
+	private $time;
13
+	private $import = [];
14
+
15
+	public function __construct(\Transphporm\Cache $cache, \Transphporm\FilePath $filePath, TSSRules $tss, $time) {
16
+		$this->cache = $cache;
17
+		$this->filePath = $filePath;
18
+		$this->tss = $tss;
19
+		$this->time = isset($time) ? $time : time();
20
+	}
21 21
 
22 22
 	//Allows controlling whether any updates are required to the template
23 23
 	//e.g. return false
Please login to merge, or discard this patch.
src/Parser/Tokenizer/Brackets.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@
 block discarded – undo
10 10
 
11 11
 class Brackets implements \Transphporm\Parser\Tokenizable {
12 12
 
13
-	private $types =  [
13
+	private $types = [
14 14
 			Tokenizer::OPEN_BRACKET => ['(', ')'],
15 15
 			Tokenizer::OPEN_BRACE => ['{', '}'],
16 16
 			Tokenizer::OPEN_SQUARE_BRACKET => ['[', ']']
Please login to merge, or discard this patch.
src/SheetLoader/TSSFile.php 3 patches
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -17,8 +17,8 @@  discard block
 block discarded – undo
17 17
 		$this->fileName = $fileName;
18 18
 		$this->filePath = $filePath;
19 19
 		$this->cache = $cache;
20
-	    $this->time = isset($time) ? $time : time();
21
-	    $this->cacheName = $this->fileName;
20
+		$this->time = isset($time) ? $time : time();
21
+		$this->cacheName = $this->fileName;
22 22
 	}
23 23
 
24 24
 	private function getRulesFromCache($file) {
@@ -77,15 +77,15 @@  discard block
 block discarded – undo
77 77
 	}
78 78
 
79 79
 	//write the sheet to cache
80
-    public function write($rules, $imports = []) {
80
+	public function write($rules, $imports = []) {
81 81
 		$existing = $this->cache->load($this->fileName, filemtime($this->fileName));
82 82
 		if (isset($existing['import']) && empty($imports)) $imports = $existing['import'];
83 83
 		$this->cache->write($this->cacheName, ['rules' => $rules, 'import' => $imports, 'minFreq' => $this->getMinUpdateFreq($rules), 'ctime' => $this->time, 'cacheKey' => $this->cacheKey]);
84 84
 
85 85
 		return $rules;
86
-    }
86
+	}
87 87
 
88
-    //Gets the minimum update-frequency for a sheet's rules
88
+	//Gets the minimum update-frequency for a sheet's rules
89 89
 	private function getMinUpdateFreq($rules) {
90 90
 		$min = \PHP_INT_MAX;
91 91
 
Please login to merge, or discard this patch.
Braces   +22 added lines, -8 removed lines patch added patch discarded remove patch
@@ -32,7 +32,9 @@  discard block
 block discarded – undo
32 32
 		if ($rules) {
33 33
 			foreach ($rules['import'] as $file) {
34 34
 				//Check that the import file hasn't been changed since the cache was written
35
-				if (filemtime($file) > $rules['ctime']) return false;
35
+				if (filemtime($file) > $rules['ctime']) {
36
+					return false;
37
+				}
36 38
 			}
37 39
 		}
38 40
 
@@ -48,10 +50,14 @@  discard block
 block discarded – undo
48 50
 
49 51
 		$rules = $this->getRulesFromCache($this->fileName);
50 52
 		//Nothing was cached or the TSS file has changed, update is required
51
-		if (empty($rules)) return true;
53
+		if (empty($rules)) {
54
+			return true;
55
+		}
52 56
 
53 57
 		//Find the sheet's minimum update-frequency, if it hasn't passed then no updates are required
54
-		if ($rules['ctime']+$rules['minFreq'] <= $this->time) return true;
58
+		if ($rules['ctime']+$rules['minFreq'] <= $this->time) {
59
+			return true;
60
+		}
55 61
 
56 62
 		return false;
57 63
 	}
@@ -63,15 +69,19 @@  discard block
 block discarded – undo
63 69
 			$cacheKey = $parser->parseTokens($this->cacheKey)[0];
64 70
 			$this->cacheName = $cacheKey . $this->fileName;
65 71
 			return $cacheKey;
72
+		} else {
73
+			return $this->fileName;
66 74
 		}
67
-		else return $this->fileName;
68 75
 	}
69 76
 
70 77
 	public function getRules($cssToXpath, $valueParser, $sheetLoader, $indexStart) {
71 78
 		$rules = $this->getRulesFromCache($this->fileName)['rules'];
72 79
 		$this->filePath->addPath(dirname(realpath($this->fileName)));
73
-		if (empty($rules)) $tss = file_get_contents($this->fileName);
74
-		else return $rules;
80
+		if (empty($rules)) {
81
+			$tss = file_get_contents($this->fileName);
82
+		} else {
83
+			return $rules;
84
+		}
75 85
 
76 86
 		return $tss == null ? [] : (new \Transphporm\Parser\Sheet($tss, $cssToXpath, $valueParser, $this->filePath, $sheetLoader))->parse($indexStart);
77 87
 	}
@@ -79,7 +89,9 @@  discard block
 block discarded – undo
79 89
 	//write the sheet to cache
80 90
     public function write($rules, $imports = []) {
81 91
 		$existing = $this->cache->load($this->fileName, filemtime($this->fileName));
82
-		if (isset($existing['import']) && empty($imports)) $imports = $existing['import'];
92
+		if (isset($existing['import']) && empty($imports)) {
93
+			$imports = $existing['import'];
94
+		}
83 95
 		$this->cache->write($this->cacheName, ['rules' => $rules, 'import' => $imports, 'minFreq' => $this->getMinUpdateFreq($rules), 'ctime' => $this->time, 'cacheKey' => $this->cacheKey]);
84 96
 
85 97
 		return $rules;
@@ -91,7 +103,9 @@  discard block
 block discarded – undo
91 103
 
92 104
 		foreach ($rules as $rule) {
93 105
 			$ruleFreq = $rule->getUpdateFrequency();
94
-			if ($ruleFreq < $min) $min = $ruleFreq;
106
+			if ($ruleFreq < $min) {
107
+				$min = $ruleFreq;
108
+			}
95 109
 		}
96 110
 
97 111
 		return $min;
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -61,7 +61,7 @@
 block discarded – undo
61 61
 		if ($this->cacheKey) {
62 62
 			$parser = new \Transphporm\Parser\Value($data);
63 63
 			$cacheKey = $parser->parseTokens($this->cacheKey)[0];
64
-			$this->cacheName = $cacheKey . $this->fileName;
64
+			$this->cacheName = $cacheKey.$this->fileName;
65 65
 			return $cacheKey;
66 66
 		}
67 67
 		else return $this->fileName;
Please login to merge, or discard this patch.
src/TSSFunction/Constant.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@
 block discarded – undo
10 10
 	public function run(array $args, \DomElement $element) {
11 11
 		$const_name = strtoupper(trim($args[0]));
12 12
 		if (!defined($const_name)) {
13
-			throw new \Exception($const_name . ' is not a defined constant');
13
+			throw new \Exception($const_name.' is not a defined constant');
14 14
 		}
15 15
 		return constant($const_name);
16 16
 	}
Please login to merge, or discard this patch.
src/Module/Functions.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@
 block discarded – undo
21 21
 		$templateFunction = new \Transphporm\TSSFunction\Template($config->getElementData(), $config->getCssToXpath(), $baseDir);
22 22
 		$functionSet->addFunction('template', $templateFunction);
23 23
 		$functionSet->addFunction('json', new \Transphporm\TSSFunction\Json($baseDir));
24
-        $functionSet->addFunction('constant', new \Transphporm\TSSFunction\Constant());
24
+		$functionSet->addFunction('constant', new \Transphporm\TSSFunction\Constant());
25 25
 
26 26
 		// Register HTML formatter here because it uses the template function
27 27
 		$config->registerFormatter(new \Transphporm\Formatter\HTMLFormatter($templateFunction));
Please login to merge, or discard this patch.
src/Parser/Tokens.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
 	}
40 40
 
41 41
 	public function add($token) {
42
-		if ($token instanceof Tokens) $this->tokens = array_merge($this->tokens,  $token->tokens);
42
+		if ($token instanceof Tokens) $this->tokens = array_merge($this->tokens, $token->tokens);
43 43
 		else $this->tokens[] = $token;
44 44
 	}
45 45
 
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
 			if ($token['type'] === $tokenType) $i++;
88 88
 			else $splitTokens[$i][] = $token;
89 89
 		}
90
-		return array_map(function ($tokens) {
90
+		return array_map(function($tokens) {
91 91
 			return new Tokens($tokens);
92 92
 		}, $splitTokens);
93 93
 		//return $splitTokens;
Please login to merge, or discard this patch.
Braces   +30 added lines, -11 removed lines patch added patch discarded remove patch
@@ -39,8 +39,11 @@  discard block
 block discarded – undo
39 39
 	}
40 40
 
41 41
 	public function add($token) {
42
-		if ($token instanceof Tokens) $this->tokens = array_merge($this->tokens,  $token->tokens);
43
-		else $this->tokens[] = $token;
42
+		if ($token instanceof Tokens) {
43
+			$this->tokens = array_merge($this->tokens,  $token->tokens);
44
+		} else {
45
+			$this->tokens[] = $token;
46
+		}
44 47
 	}
45 48
 
46 49
 
@@ -54,9 +57,13 @@  discard block
 block discarded – undo
54 57
 
55 58
 	private function getKeyToSlice($tokenType) {
56 59
 		$keys = $this->getKeysOfTokenType($tokenType);
57
-		if (empty($keys)) return false;
60
+		if (empty($keys)) {
61
+			return false;
62
+		}
58 63
 		$key = $keys[0];
59
-		for ($i = 0; $key < $this->iterator && isset($keys[$i]); $i++) $key = $keys[$i];
64
+		for ($i = 0; $key < $this->iterator && isset($keys[$i]); $i++) {
65
+			$key = $keys[$i];
66
+		}
60 67
 		return $key;
61 68
 	}
62 69
 
@@ -70,10 +77,17 @@  discard block
 block discarded – undo
70 77
 
71 78
 	private function sliceTokens($tokenType, $type, $increment = false) {
72 79
 		$key = $this->getKeyToSlice($tokenType);
73
-		if ($key === false) return new Tokens([]);
74
-		if ($increment) $key++;
75
-		if ($type === "from") return new Tokens(array_slice($this->tokens, $key));
76
-		else return new Tokens(array_slice($this->tokens, $this->iterator, $key));
80
+		if ($key === false) {
81
+			return new Tokens([]);
82
+		}
83
+		if ($increment) {
84
+			$key++;
85
+		}
86
+		if ($type === "from") {
87
+			return new Tokens(array_slice($this->tokens, $key));
88
+		} else {
89
+			return new Tokens(array_slice($this->tokens, $this->iterator, $key));
90
+		}
77 91
 	}
78 92
 
79 93
 	public function skip($count) {
@@ -84,8 +98,11 @@  discard block
 block discarded – undo
84 98
 		$splitTokens = [];
85 99
 		$i = 0;
86 100
 		foreach ($this->tokens as $token) {
87
-			if ($token['type'] === $tokenType) $i++;
88
-			else $splitTokens[$i][] = $token;
101
+			if ($token['type'] === $tokenType) {
102
+				$i++;
103
+			} else {
104
+				$splitTokens[$i][] = $token;
105
+			}
89 106
 		}
90 107
 		return array_map(function ($tokens) {
91 108
 			return new Tokens($tokens);
@@ -109,7 +126,9 @@  discard block
 block discarded – undo
109 126
 
110 127
 	public function removeLine() {
111 128
 		$tokens = $this->tokens;
112
-		foreach ($tokens as &$token) unset($token['line']);
129
+		foreach ($tokens as &$token) {
130
+			unset($token['line']);
131
+		}
113 132
 		return new Tokens($tokens);
114 133
 	}
115 134
 
Please login to merge, or discard this patch.
src/Formatter/Number.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -14,12 +14,12 @@
 block discarded – undo
14 14
 
15 15
 	public function decimal($num, $decimals) {
16 16
 		if (!is_numeric($num)) return $num;
17
-		return number_format((float)$num, $decimals, $this->locale['decimal_separator'], $this->locale['thousands_separator']);
17
+		return number_format((float) $num, $decimals, $this->locale['decimal_separator'], $this->locale['thousands_separator']);
18 18
 	}
19 19
 
20 20
 	public function currency($num) {
21 21
 		$num = $this->decimal($num, $this->locale['currency_decimals']);
22
-		if ($this->locale['currency_position'] === 'before') return $this->locale['currency'] . $num;
23
-		else return $num . $this->locale['currency'];
22
+		if ($this->locale['currency_position'] === 'before') return $this->locale['currency'].$num;
23
+		else return $num.$this->locale['currency'];
24 24
 	}
25 25
 }
Please login to merge, or discard this patch.
Braces   +8 added lines, -3 removed lines patch added patch discarded remove patch
@@ -13,13 +13,18 @@
 block discarded – undo
13 13
 	}
14 14
 
15 15
 	public function decimal($num, $decimals) {
16
-		if (!is_numeric($num)) return $num;
16
+		if (!is_numeric($num)) {
17
+			return $num;
18
+		}
17 19
 		return number_format((float)$num, $decimals, $this->locale['decimal_separator'], $this->locale['thousands_separator']);
18 20
 	}
19 21
 
20 22
 	public function currency($num) {
21 23
 		$num = $this->decimal($num, $this->locale['currency_decimals']);
22
-		if ($this->locale['currency_position'] === 'before') return $this->locale['currency'] . $num;
23
-		else return $num . $this->locale['currency'];
24
+		if ($this->locale['currency_position'] === 'before') {
25
+			return $this->locale['currency'] . $num;
26
+		} else {
27
+			return $num . $this->locale['currency'];
28
+		}
24 29
 	}
25 30
 }
Please login to merge, or discard this patch.
src/Hook/PostProcess.php 1 patch
Braces   +7 added lines, -3 removed lines patch added patch discarded remove patch
@@ -9,9 +9,13 @@
 block discarded – undo
9 9
 class PostProcess implements \Transphporm\Hook {
10 10
 	public function run(\DomElement $element) {
11 11
 		$transphporm = $element->getAttribute('transphporm');
12
-		if ($transphporm === 'remove') $element->parentNode->removeChild($element);
13
-		else if ($transphporm === 'text') $element->parentNode->replaceChild($element->firstChild, $element);
14
-		else $element->removeAttribute('transphporm');
12
+		if ($transphporm === 'remove') {
13
+			$element->parentNode->removeChild($element);
14
+		} else if ($transphporm === 'text') {
15
+			$element->parentNode->replaceChild($element->firstChild, $element);
16
+		} else {
17
+			$element->removeAttribute('transphporm');
18
+		}
15 19
 	}
16 20
 
17 21
 	public function runOnImmutableElements(): bool {
Please login to merge, or discard this patch.