Completed
Pull Request — master (#145)
by
unknown
02:31
created
src/FilePath.php 3 patches
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.
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -2,20 +2,20 @@
 block discarded – undo
2 2
 namespace Transphporm;
3 3
 
4 4
 class FilePath {
5
-    private $baseDir;
6
-    private $customBase;
5
+	private $baseDir;
6
+	private $customBase;
7 7
 
8
-    public function __construct($customBase = null) {
9
-        $this->baseDir = "";
10
-        if ($customBase === null) $this->customBase = getcwd();
11
-        else $this->customBase = rtrim($customBase, '/');
12
-    }
8
+	public function __construct($customBase = null) {
9
+		$this->baseDir = "";
10
+		if ($customBase === null) $this->customBase = getcwd();
11
+		else $this->customBase = rtrim($customBase, '/');
12
+	}
13 13
 
14
-    public function setBaseDir($baseDir) {
15
-        $this->baseDir = $baseDir;
16
-    }
14
+	public function setBaseDir($baseDir) {
15
+		$this->baseDir = $baseDir;
16
+	}
17 17
 
18
-    public function getFilePath($filePath = "") {
18
+	public function getFilePath($filePath = "") {
19 19
 		if (isset($filePath[0]) && $filePath[0] == "/") return $this->customBase . $filePath;
20 20
 		else return $this->baseDir . $filePath;
21 21
 	}
Please login to merge, or discard this patch.
Braces   +10 added lines, -4 removed lines patch added patch discarded remove patch
@@ -7,8 +7,11 @@  discard block
 block discarded – undo
7 7
 
8 8
     public function __construct($customBase = null) {
9 9
         $this->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 setBaseDir($baseDir) {
@@ -16,7 +19,10 @@  discard block
 block discarded – undo
16 19
     }
17 20
 
18 21
     public function getFilePath($filePath = "") {
19
-		if (isset($filePath[0]) && $filePath[0] == "/") return $this->customBase . $filePath;
20
-		else return $this->baseDir . $filePath;
22
+		if (isset($filePath[0]) && $filePath[0] == "/") {
23
+			return $this->customBase . $filePath;
24
+		} else {
25
+			return $this->baseDir . $filePath;
26
+		}
21 27
 	}
22 28
 }
Please login to merge, or discard this patch.
src/Parser/ValueData.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -48,7 +48,7 @@
 block discarded – undo
48 48
 
49 49
 	public function extract($last, $autoLookup, $traversing) {
50 50
 		$value = $this->read($last);
51
-		if ($value && ($autoLookup || $traversing) ) {
51
+		if ($value && ($autoLookup || $traversing)) {
52 52
 			return $value;
53 53
 		}
54 54
 		throw new \UnexpectedValueException('Not found');
Please login to merge, or discard this patch.
Braces   +25 added lines, -11 removed lines patch added patch discarded remove patch
@@ -15,13 +15,17 @@  discard block
 block discarded – undo
15 15
 
16 16
 	//Read $key from array, $this->data = $this->data[$key] but also works for objects
17 17
 	private function traverseInto($key) {
18
-		if (isset($this->data->{$key})) $this->data = $this->data->{$key};
19
-		else if ($this->isArray() && isset($this->data[$key])) $this->data = $this->data[$key];
18
+		if (isset($this->data->{$key})) {
19
+			$this->data = $this->data->{$key};
20
+		} else if ($this->isArray() && isset($this->data[$key])) {
21
+			$this->data = $this->data[$key];
22
+		}
20 23
 	}
21 24
 
22 25
 	public function traverse($key, $result) {
23
-		if ($key !== null) $this->traverseInto($key);
24
-		else {
26
+		if ($key !== null) {
27
+			$this->traverseInto($key);
28
+		} else {
25 29
 			//But if the key is null, replace the data structure with the result of the last function call
26 30
 			$lastResult = $result->pop();
27 31
 			if ($lastResult) {
@@ -37,10 +41,14 @@  discard block
 block discarded – undo
37 41
 
38 42
 	public function read($value) {
39 43
 		if ($this->isArray()) {
40
-			if (isset($this->data[$value])) return $this->data[$value];
44
+			if (isset($this->data[$value])) {
45
+				return $this->data[$value];
46
+			}
47
+		} else if (isset($this->data->$value)) {
48
+			return $this->data->$value;
49
+		} else {
50
+			return null;
41 51
 		}
42
-		else if (isset($this->data->$value)) return $this->data->$value;
43
-		else return null;
44 52
 	}
45 53
 
46 54
 	public function call($func, $args) {
@@ -53,14 +61,20 @@  discard block
 block discarded – undo
53 61
 
54 62
 	public function parseNested($parser, $token, $funcName) {
55 63
 		$args = $parser->parseTokens($token['value'], $this->data);
56
-		if ($args[0] == $this->data) $args = [];
64
+		if ($args[0] == $this->data) {
65
+			$args = [];
66
+		}
57 67
 		return $this->callFuncOnObject($this->data, $funcName, $args);
58 68
 	}
59 69
 
60 70
 	private function callFuncOnObject($obj, $func, $args) {
61
-		if (isset($obj->$func) && is_callable($obj->$func)) return call_user_func_array($obj->$func, $args);
62
-		else if (is_callable([$obj, $func])) return call_user_func_array([$obj, $func], $args);
63
-		else return false;
71
+		if (isset($obj->$func) && is_callable($obj->$func)) {
72
+			return call_user_func_array($obj->$func, $args);
73
+		} else if (is_callable([$obj, $func])) {
74
+			return call_user_func_array([$obj, $func], $args);
75
+		} else {
76
+			return false;
77
+		}
64 78
 	}
65 79
 
66 80
 	public function extract($last, $autoLookup, $traversing) {
Please login to merge, or discard this patch.
src/Parser/ValueResult.php 1 patch
Braces   +5 added lines, -4 removed lines patch added patch discarded remove patch
@@ -31,10 +31,11 @@
 block discarded – undo
31 31
 		];
32 32
 
33 33
 		if ($funcs[$this->mode] === 'concat' && is_numeric($newValue)
34
-			&& is_numeric($this->result[count($this->result)-1]))
35
-			$this->add($newValue);
36
-		else
37
-			$this->{$funcs[$this->mode]}($newValue);
34
+			&& is_numeric($this->result[count($this->result)-1])) {
35
+					$this->add($newValue);
36
+		} else {
37
+					$this->{$funcs[$this->mode]}($newValue);
38
+		}
38 39
 	}
39 40
 
40 41
 	public function arg($value) {
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(['<template>' . $val . '</template>']);
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(['<template>' . $val . '</template>']);
12 12
 	}
13 13
 
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -8,12 +8,12 @@
 block discarded – undo
8 8
     }
9 9
 
10 10
     public function html($val) {
11
-		return $this->templateFunction->run(['<template>' . $val . '</template>']);
11
+		return $this->templateFunction->run(['<template>'.$val.'</template>']);
12 12
 	}
13 13
 
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/Property/Content.php 2 patches
Doc Comments   +16 added lines patch added patch discarded remove patch
@@ -28,6 +28,9 @@  discard block
 block discarded – undo
28 28
 		}
29 29
 	}
30 30
 
31
+	/**
32
+	 * @param \DOMElement $element
33
+	 */
31 34
 	private function shouldRun($element) {
32 35
 		do {
33 36
 			if ($element->getAttribute('transphporm') == 'includedtemplate') return false;
@@ -40,6 +43,10 @@  discard block
 block discarded – undo
40 43
 		return (isset($rules['content-mode'])) ? $rules['content-mode']->read() : 'append';
41 44
 	}
42 45
 
46
+	/**
47
+	 * @param \DOMElement $element
48
+	 * @param \Transphporm\Hook\PseudoMatcher $pseudoMatcher
49
+	 */
43 50
 	private function processPseudo($value, $element, $pseudoMatcher) {
44 51
 		$pseudoContent = ['attr', 'header', 'before', 'after'];
45 52
 		foreach ($pseudoContent as $pseudo) {
@@ -101,6 +108,9 @@  discard block
 block discarded – undo
101 108
 		}
102 109
 	}
103 110
 
111
+	/**
112
+	 * @param \DOMElement $element
113
+	 */
104 114
 	private function replaceContent($element, $content) {
105 115
 		//If this rule was cached, the elements that were added last time need to be removed prior to running the rule again.
106 116
 		foreach ($this->getNode($content, $element->ownerDocument) as $node) {
@@ -109,12 +119,18 @@  discard block
 block discarded – undo
109 119
 		$element->setAttribute('transphporm', 'remove');
110 120
 	}
111 121
 
122
+	/**
123
+	 * @param \DOMElement $element
124
+	 */
112 125
 	private function appendContent($element, $content) {
113 126
 		foreach ($this->getNode($content, $element->ownerDocument) as $node) {
114 127
 			$element->appendChild($node);
115 128
 		}
116 129
 	}
117 130
 
131
+	/**
132
+	 * @param \DOMElement $element
133
+	 */
118 134
 	private function removeAllChildren($element) {
119 135
 		while ($element->hasChildNodes()) $element->removeChild($element->firstChild);
120 136
 	}
Please login to merge, or discard this patch.
Braces   +22 added lines, -11 removed lines patch added patch discarded remove patch
@@ -15,7 +15,9 @@  discard block
 block discarded – undo
15 15
 	}
16 16
 
17 17
 	public function run(array $values, \DomElement $element, array $rules, \Transphporm\Hook\PseudoMatcher $pseudoMatcher, array $properties = []) {
18
-		if (!$this->shouldRun($element)) return false;
18
+		if (!$this->shouldRun($element)) {
19
+			return false;
20
+		}
19 21
 
20 22
 		$values = $this->formatter->format($values, $rules);
21 23
 
@@ -23,14 +25,19 @@  discard block
 block discarded – undo
23 25
 			//Remove the current contents
24 26
 			$this->removeAllChildren($element);
25 27
 			//Now make a text node
26
-			if ($this->getContentMode($rules) === 'replace') $this->replaceContent($element, $values);
27
-			else $this->appendContent($element, $values);
28
+			if ($this->getContentMode($rules) === 'replace') {
29
+				$this->replaceContent($element, $values);
30
+			} else {
31
+				$this->appendContent($element, $values);
32
+			}
28 33
 		}
29 34
 	}
30 35
 
31 36
 	private function shouldRun($element) {
32 37
 		do {
33
-			if ($element->getAttribute('transphporm') == 'includedtemplate') return false;
38
+			if ($element->getAttribute('transphporm') == 'includedtemplate') {
39
+				return false;
40
+			}
34 41
 		}
35 42
 		while (($element = $element->parentNode) instanceof \DomElement);
36 43
 		return true;
@@ -54,9 +61,10 @@  discard block
 block discarded – undo
54 61
 	private function getNode($node, $document) {
55 62
 		foreach ($node as $n) {
56 63
 			if (is_array($n)) {
57
-				foreach ($this->getNode($n, $document) as $new) yield $new;
58
-			}
59
-			else {
64
+				foreach ($this->getNode($n, $document) as $new) {
65
+					yield $new;
66
+				}
67
+			} else {
60 68
 				yield $this->convertNode($n, $document);
61 69
 			}
62 70
 		}
@@ -67,9 +75,10 @@  discard block
 block discarded – undo
67 75
 			$new = $document->importNode($node, true);
68 76
 			//Removing this might cause problems with caching...
69 77
 			//$new->setAttribute('transphporm', 'added');
70
-		}
71
-		else {
72
-			if ($node instanceof \DomText) $node = $node->nodeValue;
78
+		} else {
79
+			if ($node instanceof \DomText) {
80
+				$node = $node->nodeValue;
81
+			}
73 82
 			$new = $document->createElement('text');
74 83
 
75 84
 			$new->appendChild($document->createTextNode($node));
@@ -116,6 +125,8 @@  discard block
 block discarded – undo
116 125
 	}
117 126
 
118 127
 	private function removeAllChildren($element) {
119
-		while ($element->hasChildNodes()) $element->removeChild($element->firstChild);
128
+		while ($element->hasChildNodes()) {
129
+			$element->removeChild($element->firstChild);
130
+		}
120 131
 	}
121 132
 }
Please login to merge, or discard this patch.
src/Module/Format.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -15,8 +15,8 @@
 block discarded – undo
15 15
 
16 16
 	private function getLocale() {
17 17
 		if (is_array($this->locale)) return $this->locale;
18
-		else if (strlen($this->locale) > 0) return json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . '../Formatter' . DIRECTORY_SEPARATOR . 'Locale' . DIRECTORY_SEPARATOR . $this->locale . '.json'), true);
19
-		else return json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . '../Formatter' . DIRECTORY_SEPARATOR . 'Locale' . DIRECTORY_SEPARATOR . 'enGB.json'), true);
18
+		else if (strlen($this->locale) > 0) return json_decode(file_get_contents(__DIR__.DIRECTORY_SEPARATOR.'../Formatter'.DIRECTORY_SEPARATOR.'Locale'.DIRECTORY_SEPARATOR.$this->locale.'.json'), true);
19
+		else return json_decode(file_get_contents(__DIR__.DIRECTORY_SEPARATOR.'../Formatter'.DIRECTORY_SEPARATOR.'Locale'.DIRECTORY_SEPARATOR.'enGB.json'), true);
20 20
 	}
21 21
 
22 22
 	public function load(\Transphporm\Config $config) {
Please login to merge, or discard this patch.
Braces   +7 added lines, -3 removed lines patch added patch discarded remove patch
@@ -14,9 +14,13 @@
 block discarded – undo
14 14
 	}
15 15
 
16 16
 	private function getLocale() {
17
-		if (is_array($this->locale)) return $this->locale;
18
-		else if (strlen($this->locale) > 0) return json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . '../Formatter' . DIRECTORY_SEPARATOR . 'Locale' . DIRECTORY_SEPARATOR . $this->locale . '.json'), true);
19
-		else return json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . '../Formatter' . DIRECTORY_SEPARATOR . 'Locale' . DIRECTORY_SEPARATOR . 'enGB.json'), true);
17
+		if (is_array($this->locale)) {
18
+			return $this->locale;
19
+		} else if (strlen($this->locale) > 0) {
20
+			return json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . '../Formatter' . DIRECTORY_SEPARATOR . 'Locale' . DIRECTORY_SEPARATOR . $this->locale . '.json'), true);
21
+		} else {
22
+			return json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . '../Formatter' . DIRECTORY_SEPARATOR . 'Locale' . DIRECTORY_SEPARATOR . 'enGB.json'), true);
23
+		}
20 24
 	}
21 25
 
22 26
 	public function load(\Transphporm\Config $config) {
Please login to merge, or discard this patch.
src/Pseudo/Attribute.php 1 patch
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -7,7 +7,9 @@
 block discarded – undo
7 7
 namespace Transphporm\Pseudo;
8 8
 class Attribute implements \Transphporm\Pseudo {
9 9
 	public function match($name, $args, \DomElement $element) {
10
-		if (!($name === null || in_array($name, ['data', 'iteration', 'root'])))  return true;
10
+		if (!($name === null || in_array($name, ['data', 'iteration', 'root']))) {
11
+			return true;
12
+		}
11 13
 		return $args[0];
12 14
 	}
13 15
 }
Please login to merge, or discard this patch.
src/Cache.php 1 patch
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -21,7 +21,8 @@
 block discarded – undo
21 21
 		$key = md5($key);
22 22
 		if (isset($this->cache[$key]) && $this->cache[$key]['timestamp'] >= $modified) {
23 23
 			return $this->cache[$key]['content'];
24
+		} else {
25
+			return false;
24 26
 		}
25
-		else return false;
26 27
 	}
27 28
 }
28 29
\ No newline at end of file
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
@@ -20,8 +20,7 @@  discard block
 block discarded – undo
20 20
 			if (isset($this->functions[$name])) {
21 21
 				return $this->functions[$name]->run($this->getArgs0($name, $args), $this->element);
22 22
 			}
23
-		}
24
-		catch (\Exception $e) {
23
+		} catch (\Exception $e) {
25 24
 			throw new RunException(Exception::TSS_FUNCTION, $name, $e);
26 25
 		}
27 26
 		return true;
@@ -32,8 +31,7 @@  discard block
 block discarded – undo
32 31
 			$tokens = $args[0];
33 32
 			$parser = new \Transphporm\Parser\Value($this);
34 33
 			return $parser->parseTokens($tokens, $this->elementData->getData($this->element));
35
-		}
36
-		else if ($args[0] instanceof Parser\Tokens) {
34
+		} else if ($args[0] instanceof Parser\Tokens) {
37 35
 			return iterator_to_array($args[0]);
38 36
 		}
39 37
 
Please login to merge, or discard this patch.