Completed
Push — master ( 247d83...132dc2 )
by Tom
02:31
created
src/FunctionSet.php 1 patch
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -19,8 +19,9 @@
 block discarded – undo
19 19
 	public function __call($name, $args) {
20 20
 		if (isset($this->functions[$name])) {
21 21
 			return $this->functions[$name]->run($args[0], $args[1]);
22
+		} else {
23
+			return \Transphporm\Parser\Value::IS_NOT_FUNCTION;
22 24
 		}
23
-		else return \Transphporm\Parser\Value::IS_NOT_FUNCTION;
24 25
 	}
25 26
 
26 27
 	public function addFunction($name, \Transphporm\TSSFunction $function) {
Please login to merge, or discard this patch.
src/Hook/ElementData.php 1 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
 	/** Binds data to an element */
19 19
 	public function bind(\DomNode $element, $data, $type = 'data') {
20 20
 		//This is a bit of a hack to workaround #24, might need a better way of doing this if it causes a problem
21
-		if (is_array($data) && $this->isObjectArray($data)) $data = $data[0];
21
+		if (is_array($data) && $this->isObjectArray($data)) {
22
+			$data = $data[0];
23
+		}
22 24
 		$content = isset($this->elementMap[$element]) ? $this->elementMap[$element] : [];
23 25
 		$content[$type] = $data;
24 26
 		$this->elementMap[$element] = $content;
@@ -31,7 +33,9 @@  discard block
 block discarded – undo
31 33
 	/** Returns the data that has been bound to $element, or, if no data is bound to $element climb the DOM tree to find the data bound to a parent node*/
32 34
 	public function getData(\DomElement $element = null, $type = 'data') {
33 35
 		while ($element) {
34
-			if (isset($this->elementMap[$element]) && isset($this->elementMap[$element][$type])) return $this->elementMap[$element][$type];
36
+			if (isset($this->elementMap[$element]) && isset($this->elementMap[$element][$type])) {
37
+				return $this->elementMap[$element][$type];
38
+			}
35 39
 			$element = $element->parentNode;
36 40
 		}
37 41
 		return $this->data;
Please login to merge, or discard this patch.
src/Pseudo/Attribute.php 1 patch
Braces   +15 added lines, -6 removed lines patch added patch discarded remove patch
@@ -14,10 +14,14 @@  discard block
 block discarded – undo
14 14
 
15 15
 	public function match($pseudo, \DomElement $element) {
16 16
 		$pos = strpos($pseudo, '[');
17
-		if ($pos === false) return true;
17
+		if ($pos === false) {
18
+			return true;
19
+		}
18 20
 		
19 21
 		$name = substr($pseudo, 0, $pos);
20
-		if (!is_callable([$this->functionSet, $name])) return true;
22
+		if (!is_callable([$this->functionSet, $name])) {
23
+			return true;
24
+		}
21 25
 
22 26
 		$bracketMatcher = new \Transphporm\Parser\BracketMatcher($pseudo);
23 27
 		$criteria = $bracketMatcher->match('[', ']');
@@ -41,16 +45,21 @@  discard block
 block discarded – undo
41 45
 	}
42 46
 
43 47
 	private function parseValue($value) {
44
-		if ($value == 'true') return true;
45
-		else if ($value == 'false') return false;
46
-		else return $value;
48
+		if ($value == 'true') {
49
+			return true;
50
+		} else if ($value == 'false') {
51
+			return false;
52
+		} else {
53
+			return $value;
54
+		}
47 55
 	}
48 56
 
49 57
 	private function getOperator($field) {
50 58
 		if ($field[strlen($field)-1] == '!') {
51 59
 			return '!';
60
+		} else {
61
+			return '';
52 62
 		}
53
-		else return '';
54 63
 	}
55 64
 
56 65
 }
57 66
\ No newline at end of file
Please login to merge, or discard this patch.
src/Property/Content.php 1 patch
Braces   +21 added lines, -9 removed lines patch added patch discarded remove patch
@@ -18,22 +18,31 @@  discard block
 block discarded – undo
18 18
 	}
19 19
 
20 20
 	public function run($value, \DomElement $element, array $rules, \Transphporm\Hook\PseudoMatcher $pseudoMatcher, array $properties = []) {
21
-		if (!$this->shouldRun($element)) return false;
21
+		if (!$this->shouldRun($element)) {
22
+			return false;
23
+		}
22 24
 			
23 25
 		$value = $this->formatter->format($value, $rules);
24 26
 		if (!$this->processPseudo($value, $element, $pseudoMatcher)) {
25 27
 			//Remove the current contents
26 28
 			$this->removeAllChildren($element);
27 29
 			//Now make a text node
28
-			if ($this->getContentMode($rules) === 'replace') $this->replaceContent($element, $value);
29
-			else $this->appendContent($element, $value);
30
+			if ($this->getContentMode($rules) === 'replace') {
31
+				$this->replaceContent($element, $value);
32
+			} else {
33
+				$this->appendContent($element, $value);
34
+			}
30 35
 		}
31 36
 	}
32 37
 
33 38
 	private function shouldRun($element) {
34
-		if ($element->getAttribute('transphporm') === 'remove') return false;
39
+		if ($element->getAttribute('transphporm') === 'remove') {
40
+			return false;
41
+		}
35 42
 		do {
36
-			if ($element->getAttribute('transphporm') == 'includedtemplate') return false;
43
+			if ($element->getAttribute('transphporm') == 'includedtemplate') {
44
+				return false;
45
+			}
37 46
 		}
38 47
 		while (($element = $element->parentNode) instanceof \DomElement);
39 48
 		return true;
@@ -60,9 +69,10 @@  discard block
 block discarded – undo
60 69
 				$new = $document->importNode($n, true);
61 70
 				//Removing this might cause problems with caching... 
62 71
 				//$new->setAttribute('transphporm', 'added');
63
-			}
64
-			else {
65
-				if ($n instanceof \DomText) $n = $n->nodeValue;
72
+			} else {
73
+				if ($n instanceof \DomText) {
74
+					$n = $n->nodeValue;
75
+				}
66 76
 				$new = $document->createElement('text');
67 77
 				$new->appendChild($document->createTextNode($n));
68 78
 				$new->setAttribute('transphporm', 'text');
@@ -108,6 +118,8 @@  discard block
 block discarded – undo
108 118
 	}
109 119
 	
110 120
 	private function removeAllChildren($element) {
111
-		while ($element->hasChildNodes()) $element->removeChild($element->firstChild);
121
+		while ($element->hasChildNodes()) {
122
+			$element->removeChild($element->firstChild);
123
+		}
112 124
 	}
113 125
 }
114 126
\ No newline at end of file
Please login to merge, or discard this patch.
src/TSSFunction/Template.php 1 patch
Braces   +6 added lines, -2 removed lines patch added patch discarded remove patch
@@ -27,7 +27,9 @@  discard block
 block discarded – undo
27 27
 		$newTemplate = new \Transphporm\Builder($this->baseDir . $args[0], $tss);
28 28
 
29 29
 		$doc = $newTemplate->output($this->elementData->getData($element), true)->body;
30
-		if ($selector != '') return $this->templateSubsection($doc, $selector);
30
+		if ($selector != '') {
31
+			return $this->templateSubsection($doc, $selector);
32
+		}
31 33
 		
32 34
 		$newNode = $doc->documentElement;
33 35
 		$result = [];
@@ -54,7 +56,9 @@  discard block
 block discarded – undo
54 56
 
55 57
 	private function getClonedElement($node, $tss) {
56 58
 		$clone = $node->cloneNode(true);
57
-		if ($tss !== null && $clone instanceof \DomElement) $clone->setAttribute('transphporm', 'includedtemplate');
59
+		if ($tss !== null && $clone instanceof \DomElement) {
60
+			$clone->setAttribute('transphporm', 'includedtemplate');
61
+		}
58 62
 		return $clone;
59 63
 	}
60 64
 }
61 65
\ No newline at end of file
Please login to merge, or discard this patch.
src/TSSFunction/Data.php 1 patch
Braces   +17 added lines, -8 removed lines patch added patch discarded remove patch
@@ -25,14 +25,18 @@  discard block
 block discarded – undo
25 25
 		$valueParser = new \Transphporm\Parser\Value($this->functionSet);
26 26
 
27 27
 		foreach ($parts as $part) {
28
-			if ($part === '') continue;
28
+			if ($part === '') {
29
+				continue;
30
+			}
29 31
 			$part = $valueParser->parse($part, $element)[0];
30 32
 
31 33
 			$funcResult = $this->traverseObj($part, $obj, $valueParser, $element);
32 34
 
33
-			if ($funcResult !== false) $obj = $funcResult;
34
-			
35
-			else $obj = $this->ifNull($obj, $part);
35
+			if ($funcResult !== false) {
36
+				$obj = $funcResult;
37
+			} else {
38
+				$obj = $this->ifNull($obj, $part);
39
+			}
36 40
 		}
37 41
 		return $obj;
38 42
 	}
@@ -41,14 +45,19 @@  discard block
 block discarded – undo
41 45
 		if (strpos($part, '(') !== false) {
42 46
 			$subObjParser = new \Transphporm\Parser\Value($obj, $valueParser, false);
43 47
 			return $subObjParser->parse($part, $element)[0];
48
+		} else if (method_exists($obj, $part)) {
49
+			return call_user_func([$obj, $part]);
50
+		} else {
51
+			return false;
44 52
 		}
45
-		else if (method_exists($obj, $part)) return call_user_func([$obj, $part]); 
46
-		else return false;
47 53
 	}
48 54
 
49 55
 	private function ifNull($obj, $key) {
50
-		if (is_array($obj)) return isset($obj[$key]) ? $obj[$key] : null;
51
-		else return isset($obj->$key) ? $obj->$key : null;
56
+		if (is_array($obj)) {
57
+			return isset($obj[$key]) ? $obj[$key] : null;
58
+		} else {
59
+			return isset($obj->$key) ? $obj->$key : null;
60
+		}
52 61
 	}
53 62
 
54 63
 
Please login to merge, or discard this patch.
src/Builder.php 1 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
@@ -47,7 +49,9 @@  discard block
 block discarded – undo
47 49
 		$data = new FunctionSet($elementData, $this->baseDir);
48 50
 		$config = new Config($data, $elementData, new Hook\Formatter(), $headers, $this->baseDir);
49 51
 
50
-		foreach ($this->modules as $module) $module->load($config);
52
+		foreach ($this->modules as $module) {
53
+			$module->load($config);
54
+		}
51 55
 		
52 56
 		$cachedOutput = $this->loadTemplate();
53 57
 		//To be a valid XML document it must have a root element, automatically wrap it in <template> to ensure it does
@@ -67,7 +71,9 @@  discard block
 block discarded – undo
67 71
 		$rules = $this->getRules($template, $valueParser);
68 72
 
69 73
 		foreach ($rules as $rule) {
70
-			if ($rule->shouldRun($this->time)) $this->executeTssRule($rule, $template, $valueParser, $config);
74
+			if ($rule->shouldRun($this->time)) {
75
+				$this->executeTssRule($rule, $template, $valueParser, $config);
76
+			}
71 77
 		}
72 78
 	}
73 79
 
@@ -92,8 +98,9 @@  discard block
 block discarded – undo
92 98
 		if (trim($this->template)[0] !== '<') {			
93 99
 			$xml = $this->cache->load($this->template, filemtime($this->template));
94 100
 			return $xml ? $xml : ['body' => file_get_contents($this->template), 'headers' => []];
101
+		} else {
102
+			return ['body' => $this->template, 'headers' => []];
95 103
 		}
96
-		else return ['body' => $this->template, 'headers' => []];	
97 104
 	}
98 105
 
99 106
 	//Load the TSS rules either from a file or as a string
@@ -107,10 +114,14 @@  discard block
 block discarded – undo
107 114
 			$key = $this->tss . $template->getPrefix() . $this->baseDir;
108 115
 			//Try to load the cached rules, if not set in the cache (or expired) parse the supplied sheet
109 116
 			$rules = $this->cache->load($key, filemtime($this->tss));
110
-			if (!$rules) return $this->cache->write($key, (new Parser\Sheet(file_get_contents($this->tss), $this->baseDir, $valueParser, $template->getPrefix()))->parse());
111
-			else return $rules;
117
+			if (!$rules) {
118
+				return $this->cache->write($key, (new Parser\Sheet(file_get_contents($this->tss), $this->baseDir, $valueParser, $template->getPrefix()))->parse());
119
+			} else {
120
+				return $rules;
121
+			}
122
+		} else {
123
+			return (new Parser\Sheet($this->tss, $this->baseDir, $valueParser, $template->getPrefix()))->parse();
112 124
 		}
113
-		else return (new Parser\Sheet($this->tss, $this->baseDir, $valueParser, $template->getPrefix()))->parse();
114 125
 	}
115 126
 
116 127
 	public function setCache(\ArrayAccess $cache) {
Please login to merge, or discard this patch.