Completed
Push — master ( 5ec81c...d5ea32 )
by Richard
03:52
created
src/Config.php 1 patch
Doc Comments   +6 added lines patch added patch discarded remove patch
@@ -35,6 +35,9 @@  discard block
 block discarded – undo
35 35
 		return $this->headers;
36 36
 	}
37 37
 
38
+	/**
39
+	 * @return FilePath
40
+	 */
38 41
 	public function getFilePath() {
39 42
 		return $this->filePath;
40 43
 	}
@@ -63,6 +66,9 @@  discard block
 block discarded – undo
63 66
 		return $this->valueParser;
64 67
 	}
65 68
 
69
+	/**
70
+	 * @param string $name
71
+	 */
66 72
 	public function registerProperty($name, Property $property) {
67 73
 		$this->properties[$name] = $property;
68 74
 	}
Please login to merge, or discard this patch.
src/TSSFunction/Template.php 2 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -17,6 +17,9 @@
 block discarded – undo
17 17
 		$this->xPath = $xPath;
18 18
 	}
19 19
 
20
+	/**
21
+	 * @param integer $index
22
+	 */
20 23
 	private function readArray($array, $index) {
21 24
 		return isset($array[$index]) ? $array[$index] : null;
22 25
 	}
Please login to merge, or discard this patch.
Braces   +11 added lines, -4 removed lines patch added patch discarded remove patch
@@ -25,13 +25,18 @@  discard block
 block discarded – undo
25 25
 		$selector = $this->readArray($args, 1);
26 26
 		$tss = $this->readArray($args, 2);
27 27
 
28
-		if (trim($args[0])[0] === '<') $xml = $args[0];
29
-		else $xml = $this->filePath->getFilePath($args[0]);
28
+		if (trim($args[0])[0] === '<') {
29
+			$xml = $args[0];
30
+		} else {
31
+			$xml = $this->filePath->getFilePath($args[0]);
32
+		}
30 33
 
31 34
 		$newTemplate = new \Transphporm\Builder($xml, $tss ? $this->filePath->getFilePath($tss) : null);
32 35
 
33 36
 		$doc = $newTemplate->output($this->elementData->getData($element), true)->body;
34
-		if ($selector != '') return $this->templateSubsection($doc, $selector);
37
+		if ($selector != '') {
38
+			return $this->templateSubsection($doc, $selector);
39
+		}
35 40
 
36 41
 		return $this->getTemplateContent($doc, $tss);
37 42
 
@@ -62,7 +67,9 @@  discard block
 block discarded – undo
62 67
 
63 68
 	private function getClonedElement($node, $tss) {
64 69
 		$clone = $node->cloneNode(true);
65
-		if ($tss != null && $clone instanceof \DomElement) $clone->setAttribute('transphporm', 'includedtemplate');
70
+		if ($tss != null && $clone instanceof \DomElement) {
71
+			$clone->setAttribute('transphporm', 'includedtemplate');
72
+		}
66 73
 		return $clone;
67 74
 	}
68 75
 }
Please login to merge, or discard this patch.
src/TSSFunction/Json.php 2 patches
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -1,29 +1,29 @@
 block discarded – undo
1 1
 <?php
2 2
 namespace Transphporm\TSSFunction;
3 3
 class Json implements \Transphporm\TSSFunction {
4
-    private $baseDir;
4
+	private $baseDir;
5 5
 
6
-    public function __construct(\Transphporm\FilePath $filePath) {
7
-        $this->filePath = $filePath;
8
-    }
6
+	public function __construct(\Transphporm\FilePath $filePath) {
7
+		$this->filePath = $filePath;
8
+	}
9 9
 
10
-    public function run(array $args, \DomElement $element = null) {
11
-        $json = $args[0];
10
+	public function run(array $args, \DomElement $element = null) {
11
+		$json = $args[0];
12 12
 
13
-        if ($this->isJsonFile($json)) {
14
-            $path = $this->filePath->getFilePath($json);
15
-            if (!file_exists($path)) throw new \Exception('File does not exist at: ' . $path);
16
-            $json = file_get_contents($path);
17
-        }
13
+		if ($this->isJsonFile($json)) {
14
+			$path = $this->filePath->getFilePath($json);
15
+			if (!file_exists($path)) throw new \Exception('File does not exist at: ' . $path);
16
+			$json = file_get_contents($path);
17
+		}
18 18
 
19
-        $map = json_decode($json, true);
19
+		$map = json_decode($json, true);
20 20
 
21
-        if (!is_array($map)) throw new \Exception('Could not decode json: ' . json_last_error_msg());
21
+		if (!is_array($map)) throw new \Exception('Could not decode json: ' . json_last_error_msg());
22 22
 
23
-        return $map;
24
-    }
23
+		return $map;
24
+	}
25 25
 
26
-    private function isJsonFile($json) {
27
-        return trim($json)[0] != '{' && trim($json)[0] != '[';
28
-    }
26
+	private function isJsonFile($json) {
27
+		return trim($json)[0] != '{' && trim($json)[0] != '[';
28
+	}
29 29
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -12,13 +12,13 @@
 block discarded – undo
12 12
 
13 13
         if ($this->isJsonFile($json)) {
14 14
             $path = $this->filePath->getFilePath($json);
15
-            if (!file_exists($path)) throw new \Exception('File does not exist at: ' . $path);
15
+            if (!file_exists($path)) throw new \Exception('File does not exist at: '.$path);
16 16
             $json = file_get_contents($path);
17 17
         }
18 18
 
19 19
         $map = json_decode($json, true);
20 20
 
21
-        if (!is_array($map)) throw new \Exception('Could not decode json: ' . json_last_error_msg());
21
+        if (!is_array($map)) throw new \Exception('Could not decode json: '.json_last_error_msg());
22 22
 
23 23
         return $map;
24 24
     }
Please login to merge, or discard this patch.
src/Parser/Sheet.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@
 block discarded – undo
24 24
 		if (is_file($tss)) {
25 25
 			$this->file = $tss;
26 26
 			$this->rules = $this->cache->load($tss);
27
-			$baseDir = dirname(realpath($tss)) . DIRECTORY_SEPARATOR;
27
+			$baseDir = dirname(realpath($tss)).DIRECTORY_SEPARATOR;
28 28
 			if (empty($this->rules)) $tss = file_get_contents($tss);
29 29
 			else return;
30 30
 		}
Please login to merge, or discard this patch.
Braces   +31 added lines, -13 removed lines patch added patch discarded remove patch
@@ -25,8 +25,11 @@  discard block
 block discarded – undo
25 25
 			$this->file = $tss;
26 26
 			$this->rules = $this->cache->load($tss);
27 27
 			$baseDir = dirname(realpath($tss)) . DIRECTORY_SEPARATOR;
28
-			if (empty($this->rules)) $tss = file_get_contents($tss);
29
-			else return;
28
+			if (empty($this->rules)) {
29
+				$tss = file_get_contents($tss);
30
+			} else {
31
+				return;
32
+			}
30 33
 		}
31 34
 		$this->tss = $this->stripComments($tss, '//', "\n");
32 35
 		$this->tss = $this->stripComments($this->tss, '/*', '*/');
@@ -38,7 +41,9 @@  discard block
 block discarded – undo
38 41
 	}
39 42
 
40 43
 	public function parse($indexStart = 0) {
41
-		if (!empty($this->rules)) return $this->rules['rules'];
44
+		if (!empty($this->rules)) {
45
+			return $this->rules['rules'];
46
+		}
42 47
 		$rules = $this->parseTokens($indexStart);
43 48
 		usort($rules, [$this, 'sortRules']);
44 49
 		$this->checkError($rules);
@@ -52,12 +57,12 @@  discard block
 block discarded – undo
52 57
 			if ($processing = $this->processingInstructions($token, count($this->rules)+$indexStart)) {
53 58
 				$this->rules = array_merge($this->rules, $processing);
54 59
 				continue;
55
-			}
56
-			else if ($token['type'] === Tokenizer::NEW_LINE) {
60
+			} else if ($token['type'] === Tokenizer::NEW_LINE) {
57 61
 				$line++;
58 62
 				continue;
63
+			} else {
64
+				$this->addRules($token, $indexStart, $line);
59 65
 			}
60
-			else $this->addRules($token, $indexStart, $line);
61 66
 		}
62 67
 		return $this->rules;
63 68
 	}
@@ -65,14 +70,18 @@  discard block
 block discarded – undo
65 70
 	private function addRules($token, $indexStart, $line) {
66 71
 		$selector = $this->tss->from($token['type'], true)->to(Tokenizer::OPEN_BRACE);
67 72
 		$this->tss->skip(count($selector));
68
-		if (count($selector) === 0) return;
73
+		if (count($selector) === 0) {
74
+			return;
75
+		}
69 76
 
70 77
 		$newRules = $this->cssToRules($selector, count($this->rules)+$indexStart, $this->getProperties($this->tss->current()['value']), $line);
71 78
 		$this->rules = $this->writeRule($this->rules, $newRules);
72 79
 	}
73 80
 
74 81
 	private function checkError($rules) {
75
-		if (empty($rules) && count($this->tss) > 0) throw new \Exception('No TSS rules parsed');
82
+		if (empty($rules) && count($this->tss) > 0) {
83
+			throw new \Exception('No TSS rules parsed');
84
+		}
76 85
 	}
77 86
 
78 87
 	private function CssToRules($selector, $index, $properties, $line) {
@@ -99,7 +108,9 @@  discard block
 block discarded – undo
99 108
 	}
100 109
 
101 110
 	private function processingInstructions($token, $indexStart) {
102
-		if ($token['type'] !== Tokenizer::AT_SIGN) return false;
111
+		if ($token['type'] !== Tokenizer::AT_SIGN) {
112
+			return false;
113
+		}
103 114
 		$tokens = $this->tss->from(Tokenizer::AT_SIGN, false)->to(Tokenizer::SEMI_COLON, false);
104 115
 		$funcName = $tokens->from(Tokenizer::NAME, true)->read();
105 116
 		$args = $this->valueParser->parseTokens($tokens->from(Tokenizer::NAME));
@@ -111,8 +122,11 @@  discard block
 block discarded – undo
111 122
 	}
112 123
 
113 124
 	private function import($args, $indexStart) {
114
-		if ($this->file !== null) $fileName = $fileName = $this->filePath->getFilePath($args[0]);
115
-		else $fileName = $args[0];
125
+		if ($this->file !== null) {
126
+			$fileName = $fileName = $this->filePath->getFilePath($args[0]);
127
+		} else {
128
+			$fileName = $args[0];
129
+		}
116 130
 		$this->import[] = $fileName;
117 131
 		$sheet = new Sheet($fileName, $this->baseDir, $this->xPath, $this->valueParser, $this->cache, $this->filePath);
118 132
 		return $sheet->parse($indexStart);
@@ -120,7 +134,9 @@  discard block
 block discarded – undo
120 134
 
121 135
 	private function sortRules($a, $b) {
122 136
 		//If they have the same depth, compare on index
123
-		if ($a->depth === $b->depth) return $a->index < $b->index ? -1 : 1;
137
+		if ($a->depth === $b->depth) {
138
+			return $a->index < $b->index ? -1 : 1;
139
+		}
124 140
 
125 141
 		return ($a->depth < $b->depth) ? -1 : 1;
126 142
 	}
@@ -129,7 +145,9 @@  discard block
 block discarded – undo
129 145
 		$pos = 0;
130 146
 		while (($pos = strpos($str, $open, $pos)) !== false) {
131 147
 			$end = strpos($str, $close, $pos);
132
-			if ($end === false) break;
148
+			if ($end === false) {
149
+				break;
150
+			}
133 151
 			$str = substr_replace($str, '', $pos, $end-$pos+strlen($close));
134 152
 		}
135 153
 
Please login to merge, or discard this patch.
src/FilePath.php 3 patches
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -2,16 +2,16 @@
 block discarded – undo
2 2
 namespace Transphporm;
3 3
 
4 4
 class FilePath {
5
-    private $baseDir;
6
-    private $cwd;
5
+	private $baseDir;
6
+	private $cwd;
7 7
 
8
-    public function __construct(&$baseDir, $customBase = null) {
9
-        $this->baseDir = &$baseDir;
10
-        if ($customBase === null) $this->customBase = getcwd();
11
-        else $this->customBase = rtrim($customBase, '/');
12
-    }
8
+	public function __construct(&$baseDir, $customBase = null) {
9
+		$this->baseDir = &$baseDir;
10
+		if ($customBase === null) $this->customBase = getcwd();
11
+		else $this->customBase = rtrim($customBase, '/');
12
+	}
13 13
 
14
-    public function getFilePath($filePath = "") {
14
+	public function getFilePath($filePath = "") {
15 15
 		if (isset($filePath[0]) && $filePath[0] == "/") return $this->customBase . $filePath;
16 16
 		else return $this->baseDir . $filePath;
17 17
 	}
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@
 block discarded – undo
12 12
     }
13 13
 
14 14
     public function getFilePath($filePath = "") {
15
-		if (isset($filePath[0]) && $filePath[0] == "/") return $this->customBase . $filePath;
16
-		else return $this->baseDir . $filePath;
15
+		if (isset($filePath[0]) && $filePath[0] == "/") return $this->customBase.$filePath;
16
+		else return $this->baseDir.$filePath;
17 17
 	}
18 18
 }
Please login to merge, or discard this patch.
Braces   +10 added lines, -4 removed lines patch added patch discarded remove patch
@@ -7,12 +7,18 @@
 block discarded – undo
7 7
 
8 8
     public function __construct(&$baseDir, $customBase = null) {
9 9
         $this->baseDir = &$baseDir;
10
-        if ($customBase === null) $this->customBase = getcwd();
11
-        else $this->customBase = rtrim($customBase, '/');
10
+        if ($customBase === null) {
11
+        	$this->customBase = getcwd();
12
+        } else {
13
+        	$this->customBase = rtrim($customBase, '/');
14
+        }
12 15
     }
13 16
 
14 17
     public function getFilePath($filePath = "") {
15
-		if (isset($filePath[0]) && $filePath[0] == "/") return $this->customBase . $filePath;
16
-		else return $this->baseDir . $filePath;
18
+		if (isset($filePath[0]) && $filePath[0] == "/") {
19
+			return $this->customBase . $filePath;
20
+		} else {
21
+			return $this->baseDir . $filePath;
22
+		}
17 23
 	}
18 24
 }
Please login to merge, or discard this patch.