Completed
Push — master ( 7ba91b...68752b )
by Tom
03:00
created
src/Parser/Sheet.php 2 patches
Doc Comments   +13 added lines patch added patch discarded remove patch
@@ -42,6 +42,9 @@  discard block
 block discarded – undo
42 42
 		return $this->cache->write($this->file, $rules, $this->import);
43 43
 	}
44 44
 
45
+	/**
46
+	 * @param integer $indexStart
47
+	 */
45 48
 	private function parseTokens($indexStart) {
46 49
 		$this->rules = [];
47 50
 		foreach (new TokenFilterIterator($this->tss, [Tokenizer::WHITESPACE]) as $token) {
@@ -66,6 +69,9 @@  discard block
 block discarded – undo
66 69
 		if (empty($rules) && count($this->tss) > 0) throw new \Exception('No TSS rules parsed');
67 70
 	}
68 71
 
72
+	/**
73
+	 * @param integer $index
74
+	 */
69 75
 	private function CssToRules($selector, $index, $properties, $line) {
70 76
 		$parts = $selector->trim()->splitOnToken(Tokenizer::ARG);
71 77
 		$rules = [];
@@ -89,6 +95,9 @@  discard block
 block discarded – undo
89 95
 		return $rules;
90 96
 	}
91 97
 
98
+	/**
99
+	 * @param integer $indexStart
100
+	 */
92 101
 	private function processingInstructions($token, $indexStart) {
93 102
 		if ($token['type'] !== Tokenizer::AT_SIGN) return false;
94 103
 		$tokens = $this->tss->from(Tokenizer::AT_SIGN, false)->to(Tokenizer::SEMI_COLON, false);
@@ -119,6 +128,10 @@  discard block
 block discarded – undo
119 128
 		return ($a->depth < $b->depth) ? -1 : 1;
120 129
 	}
121 130
 
131
+	/**
132
+	 * @param string $open
133
+	 * @param string $close
134
+	 */
122 135
 	private function stripComments($str, $open, $close) {
123 136
 		$pos = 0;
124 137
 		while (($pos = strpos($str, $open, $pos)) !== false) {
Please login to merge, or discard this patch.
Braces   +25 added lines, -9 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
 			$this->filePath->addPath(dirname(realpath($tss)));
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, '/*', '*/');
@@ -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);
@@ -47,8 +52,9 @@  discard block
 block discarded – undo
47 52
 		foreach (new TokenFilterIterator($this->tss, [Tokenizer::WHITESPACE]) as $token) {
48 53
 			if ($processing = $this->processingInstructions($token, count($this->rules)+$indexStart)) {
49 54
 				$this->rules = array_merge($this->rules, $processing);
55
+			} else if ($token['type'] !== Tokenizer::NEW_LINE) {
56
+				$this->addRules($token, $indexStart);
50 57
 			}
51
-			else if ($token['type'] !== Tokenizer::NEW_LINE) $this->addRules($token, $indexStart);
52 58
 		}
53 59
 		return $this->rules;
54 60
 	}
@@ -56,14 +62,18 @@  discard block
 block discarded – undo
56 62
 	private function addRules($token, $indexStart) {
57 63
 		$selector = $this->tss->from($token['type'], true)->to(Tokenizer::OPEN_BRACE);
58 64
 		$this->tss->skip(count($selector));
59
-		if (count($selector) === 0) return;
65
+		if (count($selector) === 0) {
66
+			return;
67
+		}
60 68
 
61 69
 		$newRules = $this->cssToRules($selector, count($this->rules)+$indexStart, $this->getProperties($this->tss->current()['value']), $token['line']);
62 70
 		$this->rules = $this->writeRule($this->rules, $newRules);
63 71
 	}
64 72
 
65 73
 	private function checkError($rules) {
66
-		if (empty($rules) && count($this->tss) > 0) throw new \Exception('No TSS rules parsed');
74
+		if (empty($rules) && count($this->tss) > 0) {
75
+			throw new \Exception('No TSS rules parsed');
76
+		}
67 77
 	}
68 78
 
69 79
 	private function CssToRules($selector, $index, $properties, $line) {
@@ -90,7 +100,9 @@  discard block
 block discarded – undo
90 100
 	}
91 101
 
92 102
 	private function processingInstructions($token, $indexStart) {
93
-		if ($token['type'] !== Tokenizer::AT_SIGN) return false;
103
+		if ($token['type'] !== Tokenizer::AT_SIGN) {
104
+			return false;
105
+		}
94 106
 		$tokens = $this->tss->from(Tokenizer::AT_SIGN, false)->to(Tokenizer::SEMI_COLON, false);
95 107
 		$funcName = $tokens->from(Tokenizer::NAME, true)->read();
96 108
 		$args = $this->valueParser->parseTokens($tokens->from(Tokenizer::NAME));
@@ -110,7 +122,9 @@  discard block
 block discarded – undo
110 122
 
111 123
 	private function sortRules($a, $b) {
112 124
 		//If they have the same depth, compare on index
113
-		if ($a->depth === $b->depth) return $a->index < $b->index ? -1 : 1;
125
+		if ($a->depth === $b->depth) {
126
+			return $a->index < $b->index ? -1 : 1;
127
+		}
114 128
 
115 129
 		return ($a->depth < $b->depth) ? -1 : 1;
116 130
 	}
@@ -119,7 +133,9 @@  discard block
 block discarded – undo
119 133
 		$pos = 0;
120 134
 		while (($pos = strpos($str, $open, $pos)) !== false) {
121 135
 			$end = strpos($str, $close, $pos);
122
-			if ($end === false) break;
136
+			if ($end === false) {
137
+				break;
138
+			}
123 139
 			$str = substr_replace($str, '', $pos, $end-$pos+strlen($close));
124 140
 		}
125 141
 
Please login to merge, or discard this patch.
src/FilePath.php 3 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -8,6 +8,9 @@
 block discarded – undo
8 8
 		$this->paths[] = rtrim($path, DIRECTORY_SEPARATOR);
9 9
 	}
10 10
 
11
+	/**
12
+	 * @param string $baseDir
13
+	 */
11 14
 	public function setBaseDir($baseDir) {
12 15
 		$this->baseDir = $baseDir;
13 16
 	}
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -14,15 +14,15 @@
 block discarded – undo
14 14
 
15 15
 	public function getFilePath($filePath) {
16 16
 		if (is_file($filePath)) return $filePath;
17
-		else if (is_file($this->baseDir . DIRECTORY_SEPARATOR . $filePath)) return $this->baseDir . DIRECTORY_SEPARATOR . $filePath;
17
+		else if (is_file($this->baseDir.DIRECTORY_SEPARATOR.$filePath)) return $this->baseDir.DIRECTORY_SEPARATOR.$filePath;
18 18
 		else return $this->loadFromPaths($filePath); 
19 19
 
20
-		throw new \Exception($filePath . ' not found in include path: ' . implode(';', $this->paths));
20
+		throw new \Exception($filePath.' not found in include path: '.implode(';', $this->paths));
21 21
 	}
22 22
 
23 23
 	private function loadFromPaths($filePath) {
24 24
 		foreach ($this->paths as $path) {
25
-			if (is_file($path . DIRECTORY_SEPARATOR . $filePath)) return $path . DIRECTORY_SEPARATOR . $filePath;
25
+			if (is_file($path.DIRECTORY_SEPARATOR.$filePath)) return $path.DIRECTORY_SEPARATOR.$filePath;
26 26
 		}
27 27
 	}
28 28
 }
Please login to merge, or discard this patch.
Braces   +10 added lines, -4 removed lines patch added patch discarded remove patch
@@ -13,16 +13,22 @@
 block discarded – undo
13 13
 	}
14 14
 
15 15
 	public function getFilePath($filePath) {
16
-		if (is_file($filePath)) return $filePath;
17
-		else if (is_file($this->baseDir . DIRECTORY_SEPARATOR . $filePath)) return $this->baseDir . DIRECTORY_SEPARATOR . $filePath;
18
-		else return $this->loadFromPaths($filePath); 
16
+		if (is_file($filePath)) {
17
+			return $filePath;
18
+		} else if (is_file($this->baseDir . DIRECTORY_SEPARATOR . $filePath)) {
19
+			return $this->baseDir . DIRECTORY_SEPARATOR . $filePath;
20
+		} else {
21
+			return $this->loadFromPaths($filePath);
22
+		}
19 23
 
20 24
 		throw new \Exception($filePath . ' not found in include path: ' . implode(';', $this->paths));
21 25
 	}
22 26
 
23 27
 	private function loadFromPaths($filePath) {
24 28
 		foreach ($this->paths as $path) {
25
-			if (is_file($path . DIRECTORY_SEPARATOR . $filePath)) return $path . DIRECTORY_SEPARATOR . $filePath;
29
+			if (is_file($path . DIRECTORY_SEPARATOR . $filePath)) {
30
+				return $path . DIRECTORY_SEPARATOR . $filePath;
31
+			}
26 32
 		}
27 33
 	}
28 34
 }
Please login to merge, or discard this patch.
src/Hook/PropertyHook.php 2 patches
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@  discard block
 block discarded – undo
10 10
 	private $rules;
11 11
 	private $configLine;
12 12
 	private $file;
13
-    private $filePath;
13
+	private $filePath;
14 14
 	private $line;
15 15
 	private $valueParser;
16 16
 	private $pseudoMatcher;
@@ -18,11 +18,11 @@  discard block
 block discarded – undo
18 18
 	private $functionSet;
19 19
 
20 20
 	public function __construct(array $rules, &$configLine, $file, $line, PseudoMatcher $pseudoMatcher,
21
-            \Transphporm\Parser\Value $valueParser, \Transphporm\FunctionSet $functionSet, \Transphporm\FilePath $filePath) {
21
+			\Transphporm\Parser\Value $valueParser, \Transphporm\FunctionSet $functionSet, \Transphporm\FilePath $filePath) {
22 22
 		$this->rules = $rules;
23 23
 		$this->configLine = &$configLine;
24 24
 		$this->file = $file;
25
-        $this->filePath = $filePath;
25
+		$this->filePath = $filePath;
26 26
 		$this->line = $line;
27 27
 		$this->valueParser = $valueParser;
28 28
 		$this->pseudoMatcher = $pseudoMatcher;
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
 
32 32
 	public function run(\DomElement $element) {
33 33
 		//Set the baseDir so that all files for this rule are relative to the file it came from
34
-        if ($this->file !== null) $this->filePath->setBaseDir(dirname(realpath($this->file)));
34
+		if ($this->file !== null) $this->filePath->setBaseDir(dirname(realpath($this->file)));
35 35
 		$this->functionSet->setElement($element);
36 36
 		$this->configLine = $this->line;
37 37
 		try {
Please login to merge, or discard this patch.
Braces   +14 added lines, -8 removed lines patch added patch discarded remove patch
@@ -31,15 +31,18 @@  discard block
 block discarded – undo
31 31
 
32 32
 	public function run(\DomElement $element) {
33 33
 		//Set the baseDir so that all files for this rule are relative to the file it came from
34
-        if ($this->file !== null) $this->filePath->setBaseDir(dirname(realpath($this->file)));
34
+        if ($this->file !== null) {
35
+        	$this->filePath->setBaseDir(dirname(realpath($this->file)));
36
+        }
35 37
 		$this->functionSet->setElement($element);
36 38
 		$this->configLine = $this->line;
37 39
 		try {
38 40
 			//Don't run if there's a pseudo element like nth-child() and this element doesn't match it
39
-			if (!$this->pseudoMatcher->matches($element)) return;
41
+			if (!$this->pseudoMatcher->matches($element)) {
42
+				return;
43
+			}
40 44
 			$this->callProperties($element);
41
-		}
42
-		catch (\Transphporm\RunException $e) {
45
+		} catch (\Transphporm\RunException $e) {
43 46
 			throw new \Transphporm\Exception($e, $this->file, $this->line);
44 47
 		}
45 48
 	}
@@ -50,7 +53,9 @@  discard block
 block discarded – undo
50 53
 	private function callProperties($element) {
51 54
 		foreach ($this->rules as $name => $value) {
52 55
 			$result = $this->callProperty($name, $element, $this->getArgs($value));
53
-			if ($result === false) break;
56
+			if ($result === false) {
57
+				break;
58
+			}
54 59
 		}
55 60
 	}
56 61
 	private function getArgs($value) {
@@ -65,9 +70,10 @@  discard block
 block discarded – undo
65 70
 		if (isset($this->properties[$name])) {
66 71
 			try {
67 72
 				return $this->properties[$name]->run($value, $element, $this->rules, $this->pseudoMatcher, $this->properties);
68
-			}
69
-			catch (\Exception $e) {
70
-				if ($e instanceof \Transphporm\RunException) throw $e;
73
+			} catch (\Exception $e) {
74
+				if ($e instanceof \Transphporm\RunException) {
75
+					throw $e;
76
+				}
71 77
 				throw new \Transphporm\RunException(\Transphporm\Exception::PROPERTY, $name, $e);
72 78
 			}
73 79
 		}
Please login to merge, or discard this patch.
src/TSSFunction/Template.php 1 patch
Braces   +16 added lines, -6 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->documentElement, $tss);
37 42
 	}
@@ -39,8 +44,11 @@  discard block
 block discarded – undo
39 44
 	private function getTemplateContent($newNode, $tss) {
40 45
 		$result = [];
41 46
 		foreach ($newNode->childNodes as $node) {
42
-            if (isset($node->tagName) && $node->tagName === 'template') $result[] = $this->getTemplateContent($node, $tss);
43
-			else $result[] = $this->getClonedElement($node, $tss);
47
+            if (isset($node->tagName) && $node->tagName === 'template') {
48
+            	$result[] = $this->getTemplateContent($node, $tss);
49
+            } else {
50
+				$result[] = $this->getClonedElement($node, $tss);
51
+			}
44 52
 		}
45 53
 		return $result;
46 54
 	}
@@ -59,7 +67,9 @@  discard block
 block discarded – undo
59 67
 
60 68
 	private function getClonedElement($node, $tss) {
61 69
 		$clone = $node->cloneNode(true);
62
-		if ($tss != null && $clone instanceof \DomElement) $clone->setAttribute('transphporm', 'includedtemplate');
70
+		if ($tss != null && $clone instanceof \DomElement) {
71
+			$clone->setAttribute('transphporm', 'includedtemplate');
72
+		}
63 73
 		return $clone;
64 74
 	}
65 75
 }
Please login to merge, or discard this patch.
src/Builder.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -53,7 +53,7 @@
 block discarded – undo
53 53
 
54 54
 		$cachedOutput = $this->loadTemplate();
55 55
 		//To be a valid XML document it must have a root element, automatically wrap it in <template> to ensure it does
56
-		$template = new Template($this->isValidDoc($cachedOutput['body']) ? str_ireplace('<!doctype', '<!DOCTYPE', $cachedOutput['body']) : '<template>' . $cachedOutput['body'] . '</template>' );
56
+		$template = new Template($this->isValidDoc($cachedOutput['body']) ? str_ireplace('<!doctype', '<!DOCTYPE', $cachedOutput['body']) : '<template>'.$cachedOutput['body'].'</template>');
57 57
 		$valueParser = new Parser\Value($functionSet);
58 58
 		$this->config = new Config($functionSet, $valueParser, $elementData, new Hook\Formatter(), new Parser\CssToXpath($functionSet, $template->getPrefix(), md5($this->tss)), $this->filePath, $headers);
59 59
 
Please login to merge, or discard this patch.
Braces   +11 added lines, -4 removed lines patch added patch discarded remove patch
@@ -28,7 +28,9 @@  discard block
 block discarded – undo
28 28
 		$this->cache = new Cache(new \ArrayObject());
29 29
 		$this->filePath = new FilePath();
30 30
 		$modules = is_array($modules) ? $modules : $this->defaultModules;
31
-		foreach ($modules as $module) $this->loadModule(new $module);
31
+		foreach ($modules as $module) {
32
+			$this->loadModule(new $module);
33
+		}
32 34
 	}
33 35
 
34 36
 	//Allow setting the time used by Transphporm for caching. This is for testing purposes
@@ -57,7 +59,9 @@  discard block
 block discarded – undo
57 59
 		$valueParser = new Parser\Value($functionSet);
58 60
 		$this->config = new Config($functionSet, $valueParser, $elementData, new Hook\Formatter(), new Parser\CssToXpath($functionSet, $template->getPrefix(), md5($this->tss)), $this->filePath, $headers);
59 61
 
60
-		foreach ($this->modules as $module) $module->load($this->config);
62
+		foreach ($this->modules as $module) {
63
+			$module->load($this->config);
64
+		}
61 65
 
62 66
 		$this->processRules($template, $this->config);
63 67
 
@@ -71,7 +75,9 @@  discard block
 block discarded – undo
71 75
 		$rules = $this->getRules($template, $config);
72 76
 
73 77
 		foreach ($rules as $rule) {
74
-			if ($rule->shouldRun($this->time)) $this->executeTssRule($rule, $template, $config);
78
+			if ($rule->shouldRun($this->time)) {
79
+				$this->executeTssRule($rule, $template, $config);
80
+			}
75 81
 		}
76 82
 	}
77 83
 
@@ -96,8 +102,9 @@  discard block
 block discarded – undo
96 102
 		if (trim($this->template)[0] !== '<') {
97 103
 			$xml = $this->cache->load($this->template, filemtime($this->template));
98 104
 			return $xml ? $xml : ['body' => file_get_contents($this->template), 'headers' => []];
105
+		} else {
106
+			return ['body' => $this->template, 'headers' => []];
99 107
 		}
100
-		else return ['body' => $this->template, 'headers' => []];
101 108
 	}
102 109
 
103 110
 	//Load the TSS rules either from a file or as a string
Please login to merge, or discard this patch.