Completed
Push — master ( d5ea32...359d0e )
by Richard
02:05
created
src/TSSCache.php 3 patches
Indentation   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -1,13 +1,13 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 namespace Transphporm;
3 3
 class TSSCache {
4
-    private $cache;
5
-    private $prefix;
4
+	private $cache;
5
+	private $prefix;
6 6
 
7
-    public function __construct(Cache $cache, $prefix) {
8
-        $this->cache = $cache;
9
-        $this->prefix = $prefix;
10
-    }
7
+	public function __construct(Cache $cache, $prefix) {
8
+		$this->cache = $cache;
9
+		$this->prefix = $prefix;
10
+	}
11 11
 
12 12
 	private function getRulesFromCache($file) {
13 13
 		//The cache for the key: the filename and template prefix
@@ -28,12 +28,12 @@  discard block
 block discarded – undo
28 28
 		return $file . $this->prefix . dirname(realpath($file)) . DIRECTORY_SEPARATOR;
29 29
 	}
30 30
 
31
-    public function load($tss) {
32
-        return $this->getRulesFromCache($tss);
33
-    }
31
+	public function load($tss) {
32
+		return $this->getRulesFromCache($tss);
33
+	}
34 34
 
35
-    public function write($file, $rules, $imports = []) {
36
-        if (is_file($file)) $this->cache->write($this->getCacheKey($file), ['rules' => $rules, 'import' => $imports]);
37
-        return $rules;
38
-    }
35
+	public function write($file, $rules, $imports = []) {
36
+		if (is_file($file)) $this->cache->write($this->getCacheKey($file), ['rules' => $rules, 'import' => $imports]);
37
+		return $rules;
38
+	}
39 39
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@
 block discarded – undo
25 25
 	}
26 26
 
27 27
 	private function getCacheKey($file) {
28
-		return $file . $this->prefix . dirname(realpath($file)) . DIRECTORY_SEPARATOR;
28
+		return $file.$this->prefix.dirname(realpath($file)).DIRECTORY_SEPARATOR;
29 29
 	}
30 30
 
31 31
     public function load($tss) {
Please login to merge, or discard this patch.
Braces   +6 added lines, -2 removed lines patch added patch discarded remove patch
@@ -18,7 +18,9 @@  discard block
 block discarded – undo
18 18
 		$rules = $this->cache->load($key, filemtime($file));
19 19
 		if ($rules) {
20 20
 			foreach ($rules['import'] as $file) {
21
-				if (!$this->cache->load($this->getCacheKey($file), filemtime($file))) return false;
21
+				if (!$this->cache->load($this->getCacheKey($file), filemtime($file))) {
22
+					return false;
23
+				}
22 24
 			}
23 25
 		}
24 26
 		return $rules;
@@ -33,7 +35,9 @@  discard block
 block discarded – undo
33 35
     }
34 36
 
35 37
     public function write($file, $rules, $imports = []) {
36
-        if (is_file($file)) $this->cache->write($this->getCacheKey($file), ['rules' => $rules, 'import' => $imports]);
38
+        if (is_file($file)) {
39
+        	$this->cache->write($this->getCacheKey($file), ['rules' => $rules, 'import' => $imports]);
40
+        }
37 41
         return $rules;
38 42
     }
39 43
 }
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/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.
src/Parser/Value.php 1 patch
Braces   +25 added lines, -18 removed lines patch added patch discarded remove patch
@@ -50,7 +50,9 @@  discard block
 block discarded – undo
50 50
 		$this->data = new ValueData($data ? $data : $this->baseData);
51 51
 		$this->last = null;
52 52
 
53
-		if (count($tokens) <= 0) return [$data];
53
+		if (count($tokens) <= 0) {
54
+			return [$data];
55
+		}
54 56
 
55 57
 		foreach (new TokenFilterIterator($tokens, [Tokenizer::WHITESPACE, Tokenizer::NEW_LINE]) as $token) {
56 58
 			$this->{$this->tokenFuncs[$token['type']]}($token);
@@ -72,13 +74,15 @@  discard block
 block discarded – undo
72 74
 	//Reads the last selected value from $data regardless if it's an array or object and overrides $this->data with the new value
73 75
 	//Dot moves $data to the next object in $data foo.bar moves the $data pointer from `foo` to `bar`
74 76
 	private function processDot($token) {
75
-		if ($this->last !== null) $this->data->traverse($this->last);
76
-		else {
77
+		if ($this->last !== null) {
78
+			$this->data->traverse($this->last);
79
+		} else {
77 80
 			//When . is not preceeded by anything, treat it as part of the string instead of an operator
78 81
 			// foo.bar is treated as looking up `bar` in `foo` whereas .foo is treated as the string ".foo"
79 82
 			$lastResult = $this->result->pop();
80
-			if ($lastResult) $this->data = new ValueData($lastResult);
81
-			else {
83
+			if ($lastResult) {
84
+				$this->data = new ValueData($lastResult);
85
+			} else {
82 86
 				$this->processString(['value' => '.']);
83 87
 				$this->result->setMode(Tokenizer::CONCAT);
84 88
 			}
@@ -91,15 +95,19 @@  discard block
 block discarded – undo
91 95
 		$parser = new Value($this->baseData, $this->autoLookup);
92 96
 		if ($this->baseData instanceof \Transphporm\Functionset && $this->baseData->hasFunction($this->last)) {
93 97
 			$this->callTransphpormFunctions($token);
94
-		}
95
-		else {
96
-			if ($this->last !== null) $this->data->traverse($this->last);
97
-			else {
98
+		} else {
99
+			if ($this->last !== null) {
100
+				$this->data->traverse($this->last);
101
+			} else {
98 102
 				$lastResult = $this->result->pop();
99
-				if ($lastResult) $this->data = new ValueData($lastResult);
103
+				if ($lastResult) {
104
+					$this->data = new ValueData($lastResult);
105
+				}
100 106
 			}
101 107
 			$this->last = $parser->parseTokens($token['value'], null)[0];
102
-			if (!is_bool($this->last)) $this->accessingArray = true;
108
+			if (!is_bool($this->last)) {
109
+				$this->accessingArray = true;
110
+			}
103 111
 		}
104 112
 	}
105 113
 
@@ -118,8 +126,7 @@  discard block
 block discarded – undo
118 126
 	private function processBrackets($token) {
119 127
 		if ($this->baseData instanceof \Transphporm\Functionset && $this->baseData->hasFunction($this->last)) {
120 128
 			$this->callTransphpormFunctions($token);
121
-		}
122
-		else {
129
+		} else {
123 130
 			$this->processNested($token);
124 131
 		}
125 132
 	}
@@ -136,7 +143,9 @@  discard block
 block discarded – undo
136 143
 		foreach ($this->result->getResult() as $i => $value) {
137 144
 			if (is_scalar($value)) {
138 145
 				$val = $this->data->read($value);
139
-				if ($val) $this->result[$i] = $val;
146
+				if ($val) {
147
+					$this->result[$i] = $val;
148
+				}
140 149
 			}
141 150
 		}
142 151
 		$this->last = null;
@@ -148,12 +157,10 @@  discard block
 block discarded – undo
148 157
 			try {
149 158
 				$value = $this->data->extract($this->last, $this->autoLookup);
150 159
 				$this->result->processValue($value);
151
-			}
152
-			catch (\UnexpectedValueException $e) {
160
+			} catch (\UnexpectedValueException $e) {
153 161
 				if (!($this->autoLookup || $this->accessingArray)) {
154 162
 					$this->result->processValue($this->last);
155
-				}
156
-				else {
163
+				} else {
157 164
 					$this->result->clear();
158 165
 					$this->result[0] = false;
159 166
 				}
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
@@ -43,7 +43,7 @@
 block discarded – undo
43 43
 
44 44
 	public function extract($last, $autoLookup) {
45 45
 		$value = $this->read($last);
46
-		if ($value && ($autoLookup || is_array($this->data) || $this->data instanceof \ArrayAccess) ) {
46
+		if ($value && ($autoLookup || is_array($this->data) || $this->data instanceof \ArrayAccess)) {
47 47
 			return $value;
48 48
 		}
49 49
 		throw new \UnexpectedValueException('Not found');
Please login to merge, or discard this patch.
Braces   +20 added lines, -8 removed lines patch added patch discarded remove patch
@@ -14,16 +14,23 @@  discard block
 block discarded – undo
14 14
 	}
15 15
 
16 16
 	public function traverse($key) {
17
-		if (isset($this->data->{$key})) $this->data = $this->data->{$key};
18
-		else if ((is_array($this->data) || $this->data instanceof \ArrayAccess) && isset($this->data[$key])) $this->data = $this->data[$key];
17
+		if (isset($this->data->{$key})) {
18
+			$this->data = $this->data->{$key};
19
+		} else if ((is_array($this->data) || $this->data instanceof \ArrayAccess) && isset($this->data[$key])) {
20
+			$this->data = $this->data[$key];
21
+		}
19 22
 	}
20 23
 
21 24
 	public function read($value) {
22 25
 		if ((is_array($this->data) || $this->data instanceof \ArrayAccess)) {
23
-			if (isset($this->data[$value])) return $this->data[$value];
26
+			if (isset($this->data[$value])) {
27
+				return $this->data[$value];
28
+			}
29
+		} else if (isset($this->data->$value)) {
30
+			return $this->data->$value;
31
+		} else {
32
+			return false;
24 33
 		}
25
-		else if (isset($this->data->$value)) return $this->data->$value;
26
-		else return false;
27 34
 	}
28 35
 
29 36
 	public function call($func, $args) {
@@ -32,13 +39,18 @@  discard block
 block discarded – undo
32 39
 
33 40
 	public function parseNested($parser, $token, $funcName) {
34 41
 		$args = $parser->parseTokens($token['value'], $this->data);
35
-		if ($args[0] == $this->data) $args = [];
42
+		if ($args[0] == $this->data) {
43
+			$args = [];
44
+		}
36 45
 		return $this->callFuncOnObject($this->data, $funcName, $args);
37 46
 	}
38 47
 
39 48
 	private function callFuncOnObject($obj, $func, $args) {
40
-		if (isset($obj->$func) && is_callable($obj->$func)) return call_user_func_array($obj->$func, $args);
41
-		else return call_user_func_array([$obj, $func], $args);
49
+		if (isset($obj->$func) && is_callable($obj->$func)) {
50
+			return call_user_func_array($obj->$func, $args);
51
+		} else {
52
+			return call_user_func_array([$obj, $func], $args);
53
+		}
42 54
 	}
43 55
 
44 56
 	public function extract($last, $autoLookup) {
Please login to merge, or discard this patch.