Completed
Push — master ( d5ea32...359d0e )
by Richard
02:05
created
src/Parser/TokenFilterIterator.php 2 patches
Indentation   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -6,39 +6,39 @@
 block discarded – undo
6 6
  * @version         1.0                                                             */
7 7
 namespace Transphporm\Parser;
8 8
 class TokenFilterIterator implements \Iterator {
9
-    private $ignore;
10
-    private $tokens;
9
+	private $ignore;
10
+	private $tokens;
11 11
 
12
-    public function __construct(Tokens $tokens, array $ignore) {
13
-        $this->ignore = $ignore;
14
-        $this->tokens = $tokens;
15
-    }
12
+	public function __construct(Tokens $tokens, array $ignore) {
13
+		$this->ignore = $ignore;
14
+		$this->tokens = $tokens;
15
+	}
16 16
 
17
-    public function current() {
18
-        return $this->tokens->current();
19
-    }
17
+	public function current() {
18
+		return $this->tokens->current();
19
+	}
20 20
 
21
-    public function key() {
22
-        return $this->tokens->key();
23
-    }
21
+	public function key() {
22
+		return $this->tokens->key();
23
+	}
24 24
 
25
-    public function valid() {
26
-        return $this->tokens->valid();
27
-    }
25
+	public function valid() {
26
+		return $this->tokens->valid();
27
+	}
28 28
 
29
-    public function next() {
30
-        do {
31
-            $this->tokens->next();
32
-        }
33
-        while ($this->shouldContinue());
34
-    }
29
+	public function next() {
30
+		do {
31
+			$this->tokens->next();
32
+		}
33
+		while ($this->shouldContinue());
34
+	}
35 35
 
36
-    public function rewind() {
37
-        $this->tokens->rewind();
38
-        while ($this->shouldContinue()) $this->tokens->next();
39
-    }
36
+	public function rewind() {
37
+		$this->tokens->rewind();
38
+		while ($this->shouldContinue()) $this->tokens->next();
39
+	}
40 40
 
41
-    private function shouldContinue() {
42
-        return $this->tokens->valid() && in_array($this->tokens->current()['type'], $this->ignore);
43
-    }
41
+	private function shouldContinue() {
42
+		return $this->tokens->valid() && in_array($this->tokens->current()['type'], $this->ignore);
43
+	}
44 44
 }
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -35,7 +35,9 @@
 block discarded – undo
35 35
 
36 36
     public function rewind() {
37 37
         $this->tokens->rewind();
38
-        while ($this->shouldContinue()) $this->tokens->next();
38
+        while ($this->shouldContinue()) {
39
+        	$this->tokens->next();
40
+        }
39 41
     }
40 42
 
41 43
     private function shouldContinue() {
Please login to merge, or discard this patch.
src/Formatter/HTMLFormatter.php 3 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -7,6 +7,9 @@
 block discarded – undo
7 7
         $this->templateFunction = $templateFunction;
8 8
     }
9 9
 
10
+    /**
11
+     * @param string $val
12
+     */
10 13
     public function html($val) {
11 14
 		return $this->templateFunction->run([$val]);
12 15
 	}
Please login to merge, or discard this patch.
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -1,13 +1,13 @@
 block discarded – undo
1 1
 <?php
2 2
 namespace Transphporm\Formatter;
3 3
 class HTMLFormatter {
4
-    private $templateFunction;
4
+	private $templateFunction;
5 5
 
6
-    public function __construct(\Transphporm\TSSFunction\Template $templateFunction) {
7
-        $this->templateFunction = $templateFunction;
8
-    }
6
+	public function __construct(\Transphporm\TSSFunction\Template $templateFunction) {
7
+		$this->templateFunction = $templateFunction;
8
+	}
9 9
 
10
-    public function html($val) {
10
+	public function html($val) {
11 11
 		return $this->templateFunction->run([$val]);
12 12
 	}
13 13
 
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -14,6 +14,6 @@
 block discarded – undo
14 14
 	public function debug($val) {
15 15
 		ob_start();
16 16
 		var_dump($val);
17
-		return $this->html('<pre>' . ob_get_clean() . '</pre>');
17
+		return $this->html('<pre>'.ob_get_clean().'</pre>');
18 18
 	}
19 19
 }
Please login to merge, or discard this patch.
src/Builder.php 3 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.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -47,7 +47,7 @@
 block discarded – undo
47 47
 
48 48
 		$cachedOutput = $this->loadTemplate();
49 49
 		//To be a valid XML document it must have a root element, automatically wrap it in <template> to ensure it does
50
-		$template = new Template($this->isValidDoc($cachedOutput['body']) ? str_ireplace('<!doctype', '<!DOCTYPE', $cachedOutput['body']) : '<template>' . $cachedOutput['body'] . '</template>' );
50
+		$template = new Template($this->isValidDoc($cachedOutput['body']) ? str_ireplace('<!doctype', '<!DOCTYPE', $cachedOutput['body']) : '<template>'.$cachedOutput['body'].'</template>');
51 51
 		$valueParser = new Parser\Value($data);
52 52
 		$config = new Config($data, $valueParser, $elementData, new Hook\Formatter(), new Parser\CssToXpath($data, $template->getPrefix()), $headers, $this->baseDir);
53 53
 
Please login to merge, or discard this patch.
Braces   +11 added lines, -4 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
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/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.
src/Hook/PropertyHook.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@
 block discarded – undo
30 30
 
31 31
 	public function run(\DomElement $element) {
32 32
 		$this->functionSet->setElement($element);
33
-		if ($this->file !== null) $this->baseDir = dirname(realpath($this->file)) . DIRECTORY_SEPARATOR;
33
+		if ($this->file !== null) $this->baseDir = dirname(realpath($this->file)).DIRECTORY_SEPARATOR;
34 34
 		$this->configLine = $this->line;
35 35
 		try {
36 36
 			//Don't run if there's a pseudo element like nth-child() and this element doesn't match it
Please login to merge, or discard this patch.
Braces   +14 added lines, -8 removed lines patch added patch discarded remove patch
@@ -30,11 +30,15 @@  discard block
 block discarded – undo
30 30
 
31 31
 	public function run(\DomElement $element) {
32 32
 		$this->functionSet->setElement($element);
33
-		if ($this->file !== null) $this->baseDir = dirname(realpath($this->file)) . DIRECTORY_SEPARATOR;
33
+		if ($this->file !== null) {
34
+			$this->baseDir = dirname(realpath($this->file)) . DIRECTORY_SEPARATOR;
35
+		}
34 36
 		$this->configLine = $this->line;
35 37
 		try {
36 38
 			//Don't run if there's a pseudo element like nth-child() and this element doesn't match it
37
-			if (!$this->pseudoMatcher->matches($element)) return;
39
+			if (!$this->pseudoMatcher->matches($element)) {
40
+				return;
41
+			}
38 42
 
39 43
 			// TODO: Have all rule values parsed before running them so that things like `content-append` are not expecting tokens
40 44
 			// problem with this is that anything in data changed by run properties is not shown
@@ -42,10 +46,11 @@  discard block
 block discarded – undo
42 46
 
43 47
 			foreach ($this->rules as $name => $value) {
44 48
 				$result = $this->callProperty($name, $element, $this->getArgs($value));
45
-				if ($result === false) break;
49
+				if ($result === false) {
50
+					break;
51
+				}
46 52
 			}
47
-		}
48
-		catch (\Transphporm\RunException $e) {
53
+		} catch (\Transphporm\RunException $e) {
49 54
 			throw new \Transphporm\Exception($e, $this->file, $this->line);
50 55
 		}
51 56
 	}
@@ -62,9 +67,10 @@  discard block
 block discarded – undo
62 67
 		if (isset($this->properties[$name])) {
63 68
 			try {
64 69
 				return $this->properties[$name]->run($value, $element, $this->rules, $this->pseudoMatcher, $this->properties);
65
-			}
66
-			catch (\Exception $e) {
67
-				if ($e instanceof \Transphporm\RunException) throw $e;
70
+			} catch (\Exception $e) {
71
+				if ($e instanceof \Transphporm\RunException) {
72
+					throw $e;
73
+				}
68 74
 				throw new \Transphporm\RunException(\Transphporm\Exception::PROPERTY, $name, $e);
69 75
 			}
70 76
 		}
Please login to merge, or discard this patch.