Completed
Push — master ( 39abe4...b867be )
by Richard
02:31
created
src/Rule.php 2 patches
Doc Comments   +4 added lines patch added patch discarded remove patch
@@ -14,6 +14,10 @@
 block discarded – undo
14 14
 	const D = self::H*24;
15 15
 
16 16
 
17
+	/**
18
+	 * @param string $query
19
+	 * @param integer $depth
20
+	 */
17 21
 	public function __construct($query, $pseudo, $depth, $index, array $properties = []) {
18 22
 		$this->query = $query;
19 23
 		$this->pseudo = $pseudo;
Please login to merge, or discard this patch.
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@  discard block
 block discarded – undo
10 10
 	private $pseudo;
11 11
 	private $depth;
12 12
 	private $index;
13
-    private $file;
13
+	private $file;
14 14
 	private $properties = [];
15 15
 	private $lastRun = 0;
16 16
 
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
 		$this->pseudo = $pseudo;
26 26
 		$this->depth = $depth;
27 27
 		$this->index = $index;
28
-        $this->file = $file;
28
+		$this->file = $file;
29 29
 		$this->line = $line;
30 30
 		$this->properties = $properties;
31 31
 	}
Please login to merge, or discard this patch.
src/Builder.php 2 patches
Doc Comments   +8 added lines patch added patch discarded remove patch
@@ -62,6 +62,10 @@  discard block
 block discarded – undo
62 62
 		return (object) $result;
63 63
 	}
64 64
 
65
+	/**
66
+	 * @param Template $template
67
+	 * @param Config $config
68
+	 */
65 69
 	private function processRules($template, $config) {
66 70
 		$rules = $this->getRules($template, $config);
67 71
 
@@ -71,6 +75,10 @@  discard block
 block discarded – undo
71 75
 	}
72 76
 
73 77
 	//Add a postprocessing hook. This cleans up anything transphporm has added to the markup which needs to be removed
78
+
79
+	/**
80
+	 * @param Template $template
81
+	 */
74 82
 	private function doPostProcessing($template) {
75 83
 		$template->addHook('//*[@transphporm]', new Hook\PostProcess());
76 84
 		return $template;
Please login to merge, or discard this patch.
Braces   +18 added lines, -7 removed lines patch added patch discarded remove patch
@@ -26,7 +26,9 @@  discard block
 block discarded – undo
26 26
 		$this->cache = new Cache(new \ArrayObject());
27 27
 
28 28
 		$modules = is_array($modules) ? $modules : $this->defaultModules;
29
-		foreach ($modules as $module) $this->loadModule(new $module);
29
+		foreach ($modules as $module) {
30
+			$this->loadModule(new $module);
31
+		}
30 32
 	}
31 33
 
32 34
 	//Allow setting the time used by Transphporm for caching. This is for testing purposes
@@ -51,7 +53,9 @@  discard block
 block discarded – undo
51 53
 		$valueParser = new Parser\Value($data);
52 54
 		$config = new Config($data, $valueParser, $elementData, new Hook\Formatter(), new Parser\CssToXpath($data, $template->getPrefix()), $headers, $this->baseDir);
53 55
 
54
-		foreach ($this->modules as $module) $module->load($config);
56
+		foreach ($this->modules as $module) {
57
+			$module->load($config);
58
+		}
55 59
 
56 60
 		$this->processRules($template, $config);
57 61
 
@@ -66,7 +70,9 @@  discard block
 block discarded – undo
66 70
 		$rules = $this->getRules($template, $config);
67 71
 
68 72
 		foreach ($rules as $rule) {
69
-			if ($rule->shouldRun($this->time)) $this->executeTssRule($rule, $template, $config);
73
+			if ($rule->shouldRun($this->time)) {
74
+				$this->executeTssRule($rule, $template, $config);
75
+			}
70 76
 		}
71 77
 	}
72 78
 
@@ -91,8 +97,9 @@  discard block
 block discarded – undo
91 97
 		if (trim($this->template)[0] !== '<') {
92 98
 			$xml = $this->cache->load($this->template, filemtime($this->template));
93 99
 			return $xml ? $xml : ['body' => file_get_contents($this->template), 'headers' => []];
100
+		} else {
101
+			return ['body' => $this->template, 'headers' => []];
94 102
 		}
95
-		else return ['body' => $this->template, 'headers' => []];
96 103
 	}
97 104
 
98 105
 	//Load the TSS rules either from a file or as a string
@@ -107,10 +114,14 @@  discard block
 block discarded – undo
107 114
 			//Try to load the cached rules, if not set in the cache (or expired) parse the supplied sheet
108 115
 			$rules = $this->cache->load($key, filemtime($this->tss));
109 116
 
110
-			if (!$rules) return $this->cache->write($key, (new Parser\Sheet(file_get_contents($this->tss), $this->tss, $config->getCssToXpath(), $config->getValueParser()))->parse());
111
-			else return $rules;
117
+			if (!$rules) {
118
+				return $this->cache->write($key, (new Parser\Sheet(file_get_contents($this->tss), $this->tss, $config->getCssToXpath(), $config->getValueParser()))->parse());
119
+			} else {
120
+				return $rules;
121
+			}
122
+		} else {
123
+			return (new Parser\Sheet($this->tss, $this->baseDir, $config->getCssToXpath(), $config->getValueParser()))->parse();
112 124
 		}
113
-		else return (new Parser\Sheet($this->tss, $this->baseDir, $config->getCssToXpath(), $config->getValueParser()))->parse();
114 125
 	}
115 126
 
116 127
 	public function setCache(\ArrayAccess $cache) {
Please login to merge, or discard this patch.
src/Parser/Sheet.php 3 patches
Doc Comments   +14 added lines patch added patch discarded remove patch
@@ -13,6 +13,9 @@  discard block
 block discarded – undo
13 13
 	private $xPath;
14 14
 	private $tokenizer;
15 15
 
16
+	/**
17
+	 * @param string $tss
18
+	 */
16 19
 	public function __construct($tss, $file, CssToXpath $xPath, Value $valueParser) {
17 20
 		$this->tss = $this->stripComments($tss, '//', "\n");
18 21
 		$this->tss = $this->stripComments($this->tss, '/*', '*/');
@@ -52,6 +55,10 @@  discard block
 block discarded – undo
52 55
 		if (empty($rules) && count($this->tss) > 0) throw new \Exception('No TSS rules parsed');
53 56
 	}
54 57
 
58
+	/**
59
+	 * @param integer $index
60
+	 * @param integer $line
61
+	 */
55 62
 	private function CssToRules($selector, $index, $properties, $line) {
56 63
 		$parts = $selector->trim()->splitOnToken(Tokenizer::ARG);
57 64
 		$rules = [];
@@ -75,6 +82,9 @@  discard block
 block discarded – undo
75 82
 		return $rules;
76 83
 	}
77 84
 
85
+	/**
86
+	 * @param integer $indexStart
87
+	 */
78 88
 	private function processingInstructions($token, $indexStart) {
79 89
 		if ($token['type'] !== Tokenizer::AT_SIGN) return false;
80 90
 		$tokens = $this->tss->from(Tokenizer::AT_SIGN, false)->to(Tokenizer::SEMI_COLON, false);
@@ -99,6 +109,10 @@  discard block
 block discarded – undo
99 109
 		return ($a->depth < $b->depth) ? -1 : 1;
100 110
 	}
101 111
 
112
+	/**
113
+	 * @param string $open
114
+	 * @param string $close
115
+	 */
102 116
 	private function stripComments($str, $open, $close) {
103 117
 		$pos = 0;
104 118
 		while (($pos = strpos($str, $open, $pos)) !== false) {
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -86,7 +86,7 @@
 block discarded – undo
86 86
 	}
87 87
 
88 88
 	private function import($args, $indexStart) {
89
-		if ($this->file !== null) $fileName = dirname(realpath($this->file)) . DIRECTORY_SEPARATOR . $args[0];
89
+		if ($this->file !== null) $fileName = dirname(realpath($this->file)).DIRECTORY_SEPARATOR.$args[0];
90 90
 		else $fileName = $args[0];
91 91
 		$sheet = new Sheet(file_get_contents($fileName), $fileName, $this->xPath, $this->valueParser);
92 92
 		return $sheet->parse($indexStart);
Please login to merge, or discard this patch.
Braces   +21 added lines, -9 removed lines patch added patch discarded remove patch
@@ -31,14 +31,15 @@  discard block
 block discarded – undo
31 31
 				$this->tss->skip($processing['skip']+1);
32 32
 				$rules = array_merge($rules, $processing['rules']);
33 33
 				continue;
34
-			}
35
-			else if ($token['type'] === Tokenizer::NEW_LINE) {
34
+			} else if ($token['type'] === Tokenizer::NEW_LINE) {
36 35
 				$line++;
37 36
 				continue;
38 37
 			}
39 38
 			$selector = $this->tss->from($token['type'], true)->to(Tokenizer::OPEN_BRACE);
40 39
 			$this->tss->skip(count($selector));
41
-			if (count($selector) === 0) break;
40
+			if (count($selector) === 0) {
41
+				break;
42
+			}
42 43
 
43 44
 			$newRules = $this->cssToRules($selector, count($rules)+$indexStart, $this->getProperties($this->tss->current()['value']), $line);
44 45
 			$rules = $this->writeRule($rules, $newRules);
@@ -49,7 +50,9 @@  discard block
 block discarded – undo
49 50
 	}
50 51
 
51 52
 	private function checkError($rules) {
52
-		if (empty($rules) && count($this->tss) > 0) throw new \Exception('No TSS rules parsed');
53
+		if (empty($rules) && count($this->tss) > 0) {
54
+			throw new \Exception('No TSS rules parsed');
55
+		}
53 56
 	}
54 57
 
55 58
 	private function CssToRules($selector, $index, $properties, $line) {
@@ -76,7 +79,9 @@  discard block
 block discarded – undo
76 79
 	}
77 80
 
78 81
 	private function processingInstructions($token, $indexStart) {
79
-		if ($token['type'] !== Tokenizer::AT_SIGN) return false;
82
+		if ($token['type'] !== Tokenizer::AT_SIGN) {
83
+			return false;
84
+		}
80 85
 		$tokens = $this->tss->from(Tokenizer::AT_SIGN, false)->to(Tokenizer::SEMI_COLON, false);
81 86
 		$funcName = $tokens->from(Tokenizer::NAME, true)->read();
82 87
 		$args = $this->valueParser->parseTokens($tokens->from(Tokenizer::NAME));
@@ -86,15 +91,20 @@  discard block
 block discarded – undo
86 91
 	}
87 92
 
88 93
 	private function import($args, $indexStart) {
89
-		if ($this->file !== null) $fileName = dirname(realpath($this->file)) . DIRECTORY_SEPARATOR . $args[0];
90
-		else $fileName = $args[0];
94
+		if ($this->file !== null) {
95
+			$fileName = dirname(realpath($this->file)) . DIRECTORY_SEPARATOR . $args[0];
96
+		} else {
97
+			$fileName = $args[0];
98
+		}
91 99
 		$sheet = new Sheet(file_get_contents($fileName), $fileName, $this->xPath, $this->valueParser);
92 100
 		return $sheet->parse($indexStart);
93 101
 	}
94 102
 
95 103
 	private function sortRules($a, $b) {
96 104
 		//If they have the same depth, compare on index
97
-		if ($a->depth === $b->depth) return $a->index < $b->index ? -1 : 1;
105
+		if ($a->depth === $b->depth) {
106
+			return $a->index < $b->index ? -1 : 1;
107
+		}
98 108
 
99 109
 		return ($a->depth < $b->depth) ? -1 : 1;
100 110
 	}
@@ -103,7 +113,9 @@  discard block
 block discarded – undo
103 113
 		$pos = 0;
104 114
 		while (($pos = strpos($str, $open, $pos)) !== false) {
105 115
 			$end = strpos($str, $close, $pos);
106
-			if ($end === false) break;
116
+			if ($end === false) {
117
+				break;
118
+			}
107 119
 			$str = substr_replace($str, '', $pos, $end-$pos+strlen($close));
108 120
 		}
109 121
 
Please login to merge, or discard this patch.
src/FunctionSet.php 1 patch
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -21,15 +21,13 @@
 block discarded – undo
21 21
 				$tokens = $args[0];
22 22
 				$parser = new \Transphporm\Parser\Value($this);
23 23
 				$args[0] = $parser->parseTokens($tokens, $this->elementData->getData($this->element));
24
-			}
25
-			else if ($args[0] instanceof Parser\Tokens) {
24
+			} else if ($args[0] instanceof Parser\Tokens) {
26 25
 				$args[0] = iterator_to_array($args[0]);
27 26
 			}
28 27
 			if (isset($this->functions[$name])) {
29 28
 				return $this->functions[$name]->run($args[0], $this->element);
30 29
 			}
31
-		}
32
-		catch (\Exception $e) {
30
+		} catch (\Exception $e) {
33 31
 			throw new RunException(Exception::TSS_FUNCTION, $name, $e);
34 32
 		}
35 33
 		return true;
Please login to merge, or discard this patch.
src/RunException.php 2 patches
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -1,9 +1,9 @@
 block discarded – undo
1 1
 <?php
2 2
 namespace Transphporm;
3 3
 class RunException extends \Exception {
4
-    public function __construct($operationType, $operationName, \Exception $previous) {
5
-        $message = 'TSS Error: Problem carrying out ' . $operationType . ' \'' . $operationName . '\'';
4
+	public function __construct($operationType, $operationName, \Exception $previous) {
5
+		$message = 'TSS Error: Problem carrying out ' . $operationType . ' \'' . $operationName . '\'';
6 6
 
7
-        parent::__construct($message, 0, $previous);
8
-    }
7
+		parent::__construct($message, 0, $previous);
8
+	}
9 9
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@
 block discarded – undo
2 2
 namespace Transphporm;
3 3
 class RunException extends \Exception {
4 4
     public function __construct($operationType, $operationName, \Exception $previous) {
5
-        $message = 'TSS Error: Problem carrying out ' . $operationType . ' \'' . $operationName . '\'';
5
+        $message = 'TSS Error: Problem carrying out '.$operationType.' \''.$operationName.'\'';
6 6
 
7 7
         parent::__construct($message, 0, $previous);
8 8
     }
Please login to merge, or discard this patch.
src/Parser/Tokenizer.php 1 patch
Braces   +35 added lines, -14 removed lines patch added patch discarded remove patch
@@ -70,8 +70,11 @@  discard block
 block discarded – undo
70 70
 			$i += $this->doStrings($tokens, $char, $i);
71 71
 			$i += $this->doBrackets($tokens, $char, $i);
72 72
 		}
73
-		if ($returnObj) return new Tokens($tokens);
74
-		else return $tokens;
73
+		if ($returnObj) {
74
+			return new Tokens($tokens);
75
+		} else {
76
+			return $tokens;
77
+		}
75 78
 	}
76 79
 
77 80
 	private function doSimpleTokens(&$tokens, $char) {
@@ -94,10 +97,15 @@  discard block
 block discarded – undo
94 97
 	}
95 98
 
96 99
 	private function processLiterals(&$tokens, $name) {
97
-		if (is_numeric($name)) $tokens[] = ['type' => self::NUMERIC, 'value' => $name];
98
-		else if ($name == 'true') $tokens[] = ['type' => self::BOOL, 'value' => true];
99
-		else if ($name == 'false') $tokens[] = ['type' => self::BOOL, 'value' => false];
100
-		else $tokens[] = ['type' => self::NAME, 'value' => $name];
100
+		if (is_numeric($name)) {
101
+			$tokens[] = ['type' => self::NUMERIC, 'value' => $name];
102
+		} else if ($name == 'true') {
103
+			$tokens[] = ['type' => self::BOOL, 'value' => true];
104
+		} else if ($name == 'false') {
105
+			$tokens[] = ['type' => self::BOOL, 'value' => false];
106
+		} else {
107
+			$tokens[] = ['type' => self::NAME, 'value' => $name];
108
+		}
101 109
 	}
102 110
 
103 111
 	private function doBrackets(&$tokens, $char, $i) {
@@ -131,7 +139,9 @@  discard block
 block discarded – undo
131 139
 	private function extractString($pos) {
132 140
 		$char = $this->str[$pos];
133 141
 		$end = strpos($this->str, $char, $pos+1);
134
-		while ($end !== false && $this->str[$end-1] == '\\') $end = strpos($this->str, $char, $end+1);
142
+		while ($end !== false && $this->str[$end-1] == '\\') {
143
+			$end = strpos($this->str, $char, $end+1);
144
+		}
135 145
 
136 146
 		return substr($this->str, $pos+1, $end-$pos-1);
137 147
 	}
@@ -140,19 +150,27 @@  discard block
 block discarded – undo
140 150
 		$close = strpos($this->str, $closeBracket, $open);
141 151
 
142 152
 		$cPos = $open+1;
143
-		while (($cPos = strpos($this->str, $startBracket, $cPos+1)) !== false && $cPos < $close) $close = strpos($this->str, $closeBracket, $close+1);
153
+		while (($cPos = strpos($this->str, $startBracket, $cPos+1)) !== false && $cPos < $close) {
154
+			$close = strpos($this->str, $closeBracket, $close+1);
155
+		}
144 156
 		return substr($this->str, $open+1, $close-$open-1);
145 157
 	}
146 158
 
147 159
 	private function identifyChar($chr) {
148
-		if (isset($this->chars[$chr])) return $this->chars[$chr];
149
-		else return self::NAME;
160
+		if (isset($this->chars[$chr])) {
161
+			return $this->chars[$chr];
162
+		} else {
163
+			return self::NAME;
164
+		}
150 165
 	}
151 166
 
152 167
 	private function getChar($num) {
153 168
 		$chars = array_reverse($this->chars);
154
-		if (isset($chars[$num])) return $chars[$num];
155
-		else return false;
169
+		if (isset($chars[$num])) {
170
+			return $chars[$num];
171
+		} else {
172
+			return false;
173
+		}
156 174
 	}
157 175
 
158 176
 	public function serialize($tokens) {
@@ -170,8 +188,11 @@  discard block
 block discarded – undo
170 188
 
171 189
 	private function serializeValue($token) {
172 190
 		if (isset($token['value'])) {
173
-			if ($token['value'] instanceof Tokens) return $this->serialize($token['value']);
174
-			else return $token['value'];
191
+			if ($token['value'] instanceof Tokens) {
192
+				return $this->serialize($token['value']);
193
+			} else {
194
+				return $token['value'];
195
+			}
175 196
 		}
176 197
 	}
177 198
 }
Please login to merge, or discard this patch.
src/Exception.php 2 patches
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -1,14 +1,14 @@
 block discarded – undo
1 1
 <?php
2 2
 namespace Transphporm;
3 3
 class Exception extends \Exception {
4
-    const PROPERTY = 'property';
5
-    const TSS_FUNCTION = 'function';
6
-    const PSEUDO = 'pseudo';
7
-    const FORMATTER = 'formatter';
4
+	const PROPERTY = 'property';
5
+	const TSS_FUNCTION = 'function';
6
+	const PSEUDO = 'pseudo';
7
+	const FORMATTER = 'formatter';
8 8
 
9
-    public function __construct(RunException $runException, $file, $line) {
10
-        $message = $runException->getMessage() . ' on Line ' . $line . ' of ' . ($file === null ? 'tss' : $file);
9
+	public function __construct(RunException $runException, $file, $line) {
10
+		$message = $runException->getMessage() . ' on Line ' . $line . ' of ' . ($file === null ? 'tss' : $file);
11 11
 
12
-        parent::__construct($message, 0, $runException->getPrevious());
13
-    }
12
+		parent::__construct($message, 0, $runException->getPrevious());
13
+	}
14 14
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@
 block discarded – undo
7 7
     const FORMATTER = 'formatter';
8 8
 
9 9
     public function __construct(RunException $runException, $file, $line) {
10
-        $message = $runException->getMessage() . ' on Line ' . $line . ' of ' . ($file === null ? 'tss' : $file);
10
+        $message = $runException->getMessage().' on Line '.$line.' of '.($file === null ? 'tss' : $file);
11 11
 
12 12
         parent::__construct($message, 0, $runException->getPrevious());
13 13
     }
Please login to merge, or discard this patch.
src/Hook/PseudoMatcher.php 1 patch
Braces   +13 added lines, -8 removed lines patch added patch discarded remove patch
@@ -28,8 +28,7 @@  discard block
 block discarded – undo
28 28
 				try {
29 29
 					$parts = $this->getFuncParts($tokens);
30 30
 					$matches = $matches && $function->match($parts['name'], $parts['args'], $element);
31
-				}
32
-				catch (\Exception $e) {
31
+				} catch (\Exception $e) {
33 32
 					throw new \Transphporm\RunException(\Transphporm\Exception::PSEUDO, $parts['name'], $e);
34 33
 				}
35 34
 			}
@@ -42,31 +41,37 @@  discard block
 block discarded – undo
42 41
 		$parts['name'] = $this->getFuncName($tokens);
43 42
 		if ($parts['name'] === null || in_array($parts['name'], ['data', 'iteration', 'root'])) {
44 43
 			$parts['args'] = $this->valueParser->parseTokens($tokens);
45
-		}
46
-		else if (count($tokens) > 1) {
44
+		} else if (count($tokens) > 1) {
47 45
 			$tokens->rewind();
48 46
 			$tokens->next();
49 47
 			$parts['args'] = $this->valueParser->parseTokens($tokens->current()['value']);
48
+		} else {
49
+			$parts['args'] = [['']];
50 50
 		}
51
-		else $parts['args'] = [['']];
52 51
 		return $parts;
53 52
 	}
54 53
 
55 54
 	private function getFuncName($tokens) {
56
-		if ($tokens->type() === Tokenizer::NAME) return $tokens->read();
55
+		if ($tokens->type() === Tokenizer::NAME) {
56
+			return $tokens->read();
57
+		}
57 58
 		return null;
58 59
 	}
59 60
 
60 61
 	public function hasFunction($name) {
61 62
 		foreach ($this->pseudo as $tokens) {
62
-			if ($name === $this->getFuncName($tokens)) return true;
63
+			if ($name === $this->getFuncName($tokens)) {
64
+				return true;
65
+			}
63 66
 		}
64 67
 	}
65 68
 
66 69
 	public function getFuncArgs($name) {
67 70
 		foreach ($this->pseudo as $tokens) {
68 71
 			$parts = $this->getFuncParts($tokens);
69
-			if ($name === $parts['name']) return $parts['args'];
72
+			if ($name === $parts['name']) {
73
+				return $parts['args'];
74
+			}
70 75
 		}
71 76
 	}
72 77
 }
Please login to merge, or discard this patch.
src/Hook/Formatter.php 1 patch
Braces   +7 added lines, -4 removed lines patch added patch discarded remove patch
@@ -14,7 +14,9 @@  discard block
 block discarded – undo
14 14
 	}
15 15
 
16 16
 	public function format($value, $rules) {
17
-		if (!isset($rules['format'])) return $value;
17
+		if (!isset($rules['format'])) {
18
+			return $value;
19
+		}
18 20
 		$tokens = $rules['format'];
19 21
 
20 22
 		$functionName = $tokens->from(\Transphporm\Parser\Tokenizer::NAME, true)->read();
@@ -27,8 +29,7 @@  discard block
 block discarded – undo
27 29
 
28 30
 		try {
29 31
 			return $this->processFormat($options, $functionName, $value);
30
-		}
31
-		catch (\Exception $e) {
32
+		} catch (\Exception $e) {
32 33
 			throw new \Transphporm\RunException(\Transphporm\Exception::FORMATTER, $functionName, $e);
33 34
 		}
34 35
 	}
@@ -43,7 +44,9 @@  discard block
 block discarded – undo
43 44
 				}
44 45
 			}
45 46
 		}
46
-		if (!$functionExists) throw new \Exception("Formatter '$functionName' does not exist");
47
+		if (!$functionExists) {
48
+			throw new \Exception("Formatter '$functionName' does not exist");
49
+		}
47 50
 		return $value;
48 51
 	}
49 52
 }
Please login to merge, or discard this patch.