Completed
Push — master ( e38a6e...39b3df )
by Richard
02:41
created
src/TSSCache.php 3 patches
Indentation   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -1,13 +1,13 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 namespace Transphporm;
3 3
 class TSSCache {
4
-    private $cache;
5
-    private $prefix;
4
+	private $cache;
5
+	private $prefix;
6 6
 
7
-    public function __construct(Cache $cache, $prefix) {
8
-        $this->cache = $cache;
9
-        $this->prefix = $prefix;
10
-    }
7
+	public function __construct(Cache $cache, $prefix) {
8
+		$this->cache = $cache;
9
+		$this->prefix = $prefix;
10
+	}
11 11
 
12 12
 	private function getRulesFromCache($file) {
13 13
 		//The cache for the key: the filename and template prefix
@@ -28,12 +28,12 @@  discard block
 block discarded – undo
28 28
 		return $file . $this->prefix . dirname(realpath($file)) . DIRECTORY_SEPARATOR;
29 29
 	}
30 30
 
31
-    public function load($tss) {
32
-        return $this->getRulesFromCache($tss);
33
-    }
31
+	public function load($tss) {
32
+		return $this->getRulesFromCache($tss);
33
+	}
34 34
 
35
-    public function write($file, $rules, $imports = []) {
36
-        if (is_file($file)) $this->cache->write($this->getCacheKey($file), ['rules' => $rules, 'import' => $imports]);
37
-        return $rules;
38
-    }
35
+	public function write($file, $rules, $imports = []) {
36
+		if (is_file($file)) $this->cache->write($this->getCacheKey($file), ['rules' => $rules, 'import' => $imports]);
37
+		return $rules;
38
+	}
39 39
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@
 block discarded – undo
25 25
 	}
26 26
 
27 27
 	private function getCacheKey($file) {
28
-		return $file . $this->prefix . dirname(realpath($file)) . DIRECTORY_SEPARATOR;
28
+		return $file.$this->prefix.dirname(realpath($file)).DIRECTORY_SEPARATOR;
29 29
 	}
30 30
 
31 31
     public function load($tss) {
Please login to merge, or discard this patch.
Braces   +6 added lines, -2 removed lines patch added patch discarded remove patch
@@ -18,7 +18,9 @@  discard block
 block discarded – undo
18 18
 		$rules = $this->cache->load($key, filemtime($file));
19 19
 		if ($rules) {
20 20
 			foreach ($rules['import'] as $file) {
21
-				if (!$this->cache->load($this->getCacheKey($file), filemtime($file))) return false;
21
+				if (!$this->cache->load($this->getCacheKey($file), filemtime($file))) {
22
+					return false;
23
+				}
22 24
 			}
23 25
 		}
24 26
 		return $rules;
@@ -33,7 +35,9 @@  discard block
 block discarded – undo
33 35
     }
34 36
 
35 37
     public function write($file, $rules, $imports = []) {
36
-        if (is_file($file)) $this->cache->write($this->getCacheKey($file), ['rules' => $rules, 'import' => $imports]);
38
+        if (is_file($file)) {
39
+        	$this->cache->write($this->getCacheKey($file), ['rules' => $rules, 'import' => $imports]);
40
+        }
37 41
         return $rules;
38 42
     }
39 43
 }
Please login to merge, or discard this patch.
src/Parser/Sheet.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
 		if (is_file($tss)) {
23 23
 			$this->file = $tss;
24 24
 			$this->rules = $this->cache->load($tss);
25
-			$baseDir = dirname(realpath($tss)) . DIRECTORY_SEPARATOR;
25
+			$baseDir = dirname(realpath($tss)).DIRECTORY_SEPARATOR;
26 26
 			if (empty($this->rules)) $tss = file_get_contents($tss);
27 27
 			else return;
28 28
 		}
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
 	}
104 104
 
105 105
 	private function import($args, $indexStart) {
106
-		if ($this->file !== null) $fileName = dirname(realpath($this->file)) . DIRECTORY_SEPARATOR . $args[0];
106
+		if ($this->file !== null) $fileName = dirname(realpath($this->file)).DIRECTORY_SEPARATOR.$args[0];
107 107
 		else $fileName = $args[0];
108 108
 		$this->import[] = $fileName;
109 109
 		$sheet = new Sheet($fileName, $this->baseDir, $this->xPath, $this->valueParser, $this->cache);
Please login to merge, or discard this patch.
Braces   +29 added lines, -12 removed lines patch added patch discarded remove patch
@@ -23,8 +23,11 @@  discard block
 block discarded – undo
23 23
 			$this->file = $tss;
24 24
 			$this->rules = $this->cache->load($tss);
25 25
 			$baseDir = dirname(realpath($tss)) . DIRECTORY_SEPARATOR;
26
-			if (empty($this->rules)) $tss = file_get_contents($tss);
27
-			else return;
26
+			if (empty($this->rules)) {
27
+				$tss = file_get_contents($tss);
28
+			} else {
29
+				return;
30
+			}
28 31
 		}
29 32
 		$this->tss = $this->stripComments($tss, '//', "\n");
30 33
 		$this->tss = $this->stripComments($this->tss, '/*', '*/');
@@ -35,7 +38,9 @@  discard block
 block discarded – undo
35 38
 	}
36 39
 
37 40
 	public function parse($indexStart = 0) {
38
-		if (!empty($this->rules)) return $this->rules['rules'];
41
+		if (!empty($this->rules)) {
42
+			return $this->rules['rules'];
43
+		}
39 44
 		$rules = $this->parseTokens($indexStart);
40 45
 		usort($rules, [$this, 'sortRules']);
41 46
 		$this->checkError($rules);
@@ -50,14 +55,15 @@  discard block
 block discarded – undo
50 55
 				$this->tss->skip($processing['skip']+1);
51 56
 				$rules = array_merge($rules, $processing['rules']);
52 57
 				continue;
53
-			}
54
-			else if ($token['type'] === Tokenizer::NEW_LINE) {
58
+			} else if ($token['type'] === Tokenizer::NEW_LINE) {
55 59
 				$line++;
56 60
 				continue;
57 61
 			}
58 62
 			$selector = $this->tss->from($token['type'], true)->to(Tokenizer::OPEN_BRACE);
59 63
 			$this->tss->skip(count($selector));
60
-			if (count($selector) === 0) break;
64
+			if (count($selector) === 0) {
65
+				break;
66
+			}
61 67
 
62 68
 			$newRules = $this->cssToRules($selector, count($rules)+$indexStart, $this->getProperties($this->tss->current()['value']), $line);
63 69
 			$rules = $this->writeRule($rules, $newRules);
@@ -66,7 +72,9 @@  discard block
 block discarded – undo
66 72
 	}
67 73
 
68 74
 	private function checkError($rules) {
69
-		if (empty($rules) && count($this->tss) > 0) throw new \Exception('No TSS rules parsed');
75
+		if (empty($rules) && count($this->tss) > 0) {
76
+			throw new \Exception('No TSS rules parsed');
77
+		}
70 78
 	}
71 79
 
72 80
 	private function CssToRules($selector, $index, $properties, $line) {
@@ -93,7 +101,9 @@  discard block
 block discarded – undo
93 101
 	}
94 102
 
95 103
 	private function processingInstructions($token, $indexStart) {
96
-		if ($token['type'] !== Tokenizer::AT_SIGN) return false;
104
+		if ($token['type'] !== Tokenizer::AT_SIGN) {
105
+			return false;
106
+		}
97 107
 		$tokens = $this->tss->from(Tokenizer::AT_SIGN, false)->to(Tokenizer::SEMI_COLON, false);
98 108
 		$funcName = $tokens->from(Tokenizer::NAME, true)->read();
99 109
 		$args = $this->valueParser->parseTokens($tokens->from(Tokenizer::NAME));
@@ -103,8 +113,11 @@  discard block
 block discarded – undo
103 113
 	}
104 114
 
105 115
 	private function import($args, $indexStart) {
106
-		if ($this->file !== null) $fileName = dirname(realpath($this->file)) . DIRECTORY_SEPARATOR . $args[0];
107
-		else $fileName = $args[0];
116
+		if ($this->file !== null) {
117
+			$fileName = dirname(realpath($this->file)) . DIRECTORY_SEPARATOR . $args[0];
118
+		} else {
119
+			$fileName = $args[0];
120
+		}
108 121
 		$this->import[] = $fileName;
109 122
 		$sheet = new Sheet($fileName, $this->baseDir, $this->xPath, $this->valueParser, $this->cache);
110 123
 		return $sheet->parse($indexStart);
@@ -112,7 +125,9 @@  discard block
 block discarded – undo
112 125
 
113 126
 	private function sortRules($a, $b) {
114 127
 		//If they have the same depth, compare on index
115
-		if ($a->depth === $b->depth) return $a->index < $b->index ? -1 : 1;
128
+		if ($a->depth === $b->depth) {
129
+			return $a->index < $b->index ? -1 : 1;
130
+		}
116 131
 
117 132
 		return ($a->depth < $b->depth) ? -1 : 1;
118 133
 	}
@@ -121,7 +136,9 @@  discard block
 block discarded – undo
121 136
 		$pos = 0;
122 137
 		while (($pos = strpos($str, $open, $pos)) !== false) {
123 138
 			$end = strpos($str, $close, $pos);
124
-			if ($end === false) break;
139
+			if ($end === false) {
140
+				break;
141
+			}
125 142
 			$str = substr_replace($str, '', $pos, $end-$pos+strlen($close));
126 143
 		}
127 144
 
Please login to merge, or discard this patch.