Completed
Pull Request — master (#115)
by Richard
03:18
created
src/Parser/StringExtractor.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -23,8 +23,8 @@
 block discarded – undo
23 23
 			$end = strpos($str, '"', $pos+1);
24 24
 			if (!$end) break;
25 25
 			while ($str[$end-1] == '\\') $end = strpos($str, '"', $end+1);
26
-			$strings['$___STR' . ++$num] = substr($str, $pos, $end-$pos+1);
27
-			$str = substr_replace($str, '$___STR' . $num, $pos, $end-$pos+1);
26
+			$strings['$___STR'.++$num] = substr($str, $pos, $end-$pos+1);
27
+			$str = substr_replace($str, '$___STR'.$num, $pos, $end-$pos+1);
28 28
 		}
29 29
 
30 30
 		return [$str, $strings];
Please login to merge, or discard this patch.
Braces   +6 added lines, -2 removed lines patch added patch discarded remove patch
@@ -21,7 +21,9 @@  discard block
 block discarded – undo
21 21
 		$strings = [];
22 22
 		while (isset($str[$pos]) && ($pos = strpos($str, '"', $pos)) !== false) {
23 23
 			$end = strpos($str, '"', $pos+1);
24
-			if (!$end) break;
24
+			if (!$end) {
25
+				break;
26
+			}
25 27
 			$end = $this->getNextPosEscaped($str, '\\', '"', $end);
26 28
 			$strings['$___STR' . ++$num] = substr($str, $pos, $end-$pos+1);
27 29
 			$str = substr_replace($str, '$___STR' . $num, $pos, $end-$pos+1);
@@ -31,7 +33,9 @@  discard block
 block discarded – undo
31 33
 	}
32 34
 
33 35
 	private function getNextPosEscaped($str, $escape, $chr, $start) {
34
-		while ($str[$start-1] == $escape) $start = strpos($str, $chr, $start+1);
36
+		while ($str[$start-1] == $escape) {
37
+			$start = strpos($str, $chr, $start+1);
38
+		}
35 39
 		return $start;
36 40
 	}
37 41
 
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
@@ -14,8 +14,8 @@
 block discarded – undo
14 14
 
15 15
 	private function getLocale() {
16 16
 		if (is_array($this->locale)) return $this->locale;
17
-		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);
18
-		else return json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . '../Formatter' . DIRECTORY_SEPARATOR . 'Locale' . DIRECTORY_SEPARATOR . 'enGB.json'), true);
17
+		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);
18
+		else return json_decode(file_get_contents(__DIR__.DIRECTORY_SEPARATOR.'../Formatter'.DIRECTORY_SEPARATOR.'Locale'.DIRECTORY_SEPARATOR.'enGB.json'), true);
19 19
 	}
20 20
 
21 21
 	public function load(\Transphporm\FeatureSet $featureSet) {
Please login to merge, or discard this patch.
Braces   +7 added lines, -3 removed lines patch added patch discarded remove patch
@@ -13,9 +13,13 @@
 block discarded – undo
13 13
 	}
14 14
 
15 15
 	private function getLocale() {
16
-		if (is_array($this->locale)) return $this->locale;
17
-		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);
18
-		else return json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . '../Formatter' . DIRECTORY_SEPARATOR . 'Locale' . DIRECTORY_SEPARATOR . 'enGB.json'), true);
16
+		if (is_array($this->locale)) {
17
+			return $this->locale;
18
+		} else if (strlen($this->locale) > 0) {
19
+			return json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . '../Formatter' . DIRECTORY_SEPARATOR . 'Locale' . DIRECTORY_SEPARATOR . $this->locale . '.json'), true);
20
+		} else {
21
+			return json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . '../Formatter' . DIRECTORY_SEPARATOR . 'Locale' . DIRECTORY_SEPARATOR . 'enGB.json'), true);
22
+		}
19 23
 	}
20 24
 
21 25
 	public function load(\Transphporm\FeatureSet $featureSet) {
Please login to merge, or discard this patch.
src/Property/Content.php 2 patches
Doc Comments   +19 added lines patch added patch discarded remove patch
@@ -11,6 +11,9 @@  discard block
 block discarded – undo
11 11
 	private $formatter;
12 12
 
13 13
 
14
+	/**
15
+	 * @param \Transphporm\FunctionSet $data
16
+	 */
14 17
 	public function __construct($data, &$headers, \Transphporm\Hook\Formatter $formatter) {
15 18
 		$this->data = $data;
16 19
 		$this->headers = &$headers;
@@ -30,6 +33,9 @@  discard block
 block discarded – undo
30 33
 		}
31 34
 	}
32 35
 
36
+	/**
37
+	 * @param \DOMElement $element
38
+	 */
33 39
 	private function shouldRun($element) {
34 40
 		if ($element->getAttribute('transphporm') === 'remove') return false;
35 41
 		do {
@@ -43,6 +49,10 @@  discard block
 block discarded – undo
43 49
 		return (isset($rules['content-mode'])) ? $rules['content-mode'] : 'append';
44 50
 	}
45 51
 
52
+	/**
53
+	 * @param \DOMElement $element
54
+	 * @param \Transphporm\Hook\PseudoMatcher $pseudoMatcher
55
+	 */
46 56
 	private function processPseudo($value, $element, $pseudoMatcher) {
47 57
 		$pseudoContent = ['attr', 'header', 'before', 'after'];
48 58
 		foreach ($pseudoContent as $pseudo) {
@@ -93,6 +103,9 @@  discard block
 block discarded – undo
93 103
 		}			 
94 104
 	}
95 105
 
106
+	/**
107
+	 * @param \DOMElement $element
108
+	 */
96 109
 	private function replaceContent($element, $content) {
97 110
 		//If this rule was cached, the elements that were added last time need to be removed prior to running the rule again.
98 111
 		foreach ($this->getNode($content, $element->ownerDocument) as $node) {
@@ -101,12 +114,18 @@  discard block
 block discarded – undo
101 114
 		$element->setAttribute('transphporm', 'remove');
102 115
 	}
103 116
 
117
+	/**
118
+	 * @param \DOMElement $element
119
+	 */
104 120
 	private function appendContent($element, $content) {
105 121
 		foreach ($this->getNode($content, $element->ownerDocument) as $node) {
106 122
 			$element->appendChild($node);
107 123
 		}
108 124
 	}
109 125
 	
126
+	/**
127
+	 * @param \DOMElement $element
128
+	 */
110 129
 	private function removeAllChildren($element) {
111 130
 		while ($element->hasChildNodes()) $element->removeChild($element->firstChild);
112 131
 	}
Please login to merge, or discard this patch.
Braces   +18 added lines, -8 removed lines patch added patch discarded remove patch
@@ -18,15 +18,20 @@  discard block
 block discarded – undo
18 18
 	}
19 19
 
20 20
 	public function run(array $values, \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
 		$values = $this->fixValues($this->formatter->format($values, $rules));
23 25
 
24 26
 		if (!$this->processPseudo($values, $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, $values);
29
-			else $this->appendContent($element, $values);
30
+			if ($this->getContentMode($rules) === 'replace') {
31
+				$this->replaceContent($element, $values);
32
+			} else {
33
+				$this->appendContent($element, $values);
34
+			}
30 35
 		}
31 36
 	}
32 37
 
@@ -38,7 +43,9 @@  discard block
 block discarded – undo
38 43
 
39 44
 	private function shouldRun($element) {
40 45
 		do {
41
-			if ($element->getAttribute('transphporm') == 'includedtemplate') return false;
46
+			if ($element->getAttribute('transphporm') == 'includedtemplate') {
47
+				return false;
48
+			}
42 49
 		}
43 50
 		while (($element = $element->parentNode) instanceof \DomElement);
44 51
 		return true;
@@ -65,9 +72,10 @@  discard block
 block discarded – undo
65 72
 				$new = $document->importNode($n, true);
66 73
 				//Removing this might cause problems with caching... 
67 74
 				//$new->setAttribute('transphporm', 'added');
68
-			}
69
-			else {
70
-				if ($n instanceof \DomText) $n = $n->nodeValue;
75
+			} else {
76
+				if ($n instanceof \DomText) {
77
+					$n = $n->nodeValue;
78
+				}
71 79
 				$new = $document->createElement('text');
72 80
 				
73 81
 				$new->appendChild($document->createTextNode($n));
@@ -114,6 +122,8 @@  discard block
 block discarded – undo
114 122
 	}
115 123
 	
116 124
 	private function removeAllChildren($element) {
117
-		while ($element->hasChildNodes()) $element->removeChild($element->firstChild);
125
+		while ($element->hasChildNodes()) {
126
+			$element->removeChild($element->firstChild);
127
+		}
118 128
 	}
119 129
 }
120 130
\ No newline at end of file
Please login to merge, or discard this patch.
src/Formatter/StringFormatter.php 2 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -18,6 +18,9 @@
 block discarded – undo
18 18
 		return ucwords($val);
19 19
 	}
20 20
 
21
+	/**
22
+	 * @param string $val
23
+	 */
21 24
 	public function html($val) {
22 25
 		$doc = new \DomDocument();
23 26
 		$doc->loadXML($val);
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -27,6 +27,6 @@
 block discarded – undo
27 27
 	public function debug($val) {
28 28
 		ob_start();
29 29
 		var_dump($val);
30
-		return $this->html('<pre>' . ob_get_clean() . '</pre>');
30
+		return $this->html('<pre>'.ob_get_clean().'</pre>');
31 31
 	}
32 32
 }
33 33
\ No newline at end of file
Please login to merge, or discard this patch.
src/TSSFunction/Template.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@
 block discarded – undo
22 22
 	public function run(array $args, \DomElement $element) {
23 23
 		$selector = $this->readArray($args, 1);
24 24
 		$tss = $this->readArray($args, 2);
25
-		$newTemplate = new \Transphporm\Builder($this->baseDir . $args[0], $tss ? $this->baseDir . $tss : null);
25
+		$newTemplate = new \Transphporm\Builder($this->baseDir.$args[0], $tss ? $this->baseDir.$tss : null);
26 26
 
27 27
 		$doc = $newTemplate->output($this->elementData->getData($element), true)->body;
28 28
 		if ($selector != '') return $this->templateSubsection($doc, $selector);
Please login to merge, or discard this patch.
Braces   +6 added lines, -2 removed lines patch added patch discarded remove patch
@@ -30,7 +30,9 @@  discard block
 block discarded – undo
30 30
 		$newTemplate = new \Transphporm\Builder($this->baseDir . $args[0], $tss ? $this->baseDir . $tss : null);
31 31
 
32 32
 		$doc = $newTemplate->output($this->elementData->getData($element), true)->body;
33
-		if ($selector != '') return $this->templateSubsection($doc, $selector);
33
+		if ($selector != '') {
34
+			return $this->templateSubsection($doc, $selector);
35
+		}
34 36
 
35 37
 		return $this->getTemplateContent($doc, $tss);
36 38
 
@@ -60,7 +62,9 @@  discard block
 block discarded – undo
60 62
 
61 63
 	private function getClonedElement($node, $tss) {
62 64
 		$clone = $node->cloneNode(true);
63
-		if ($tss != null && $clone instanceof \DomElement) $clone->setAttribute('transphporm', 'includedtemplate');
65
+		if ($tss != null && $clone instanceof \DomElement) {
66
+			$clone->setAttribute('transphporm', 'includedtemplate');
67
+		}
64 68
 		return $clone;
65 69
 	}
66 70
 }
Please login to merge, or discard this patch.
src/Hook/ElementData.php 1 patch
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -31,7 +31,9 @@
 block discarded – undo
31 31
 	/** 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 32
 	public function getData(\DomElement $element = null, $type = 'data') {
33 33
 		while ($element) {
34
-			if (isset($this->elementMap[$element]) && isset($this->elementMap[$element][$type])) return $this->elementMap[$element][$type];
34
+			if (isset($this->elementMap[$element]) && isset($this->elementMap[$element][$type])) {
35
+				return $this->elementMap[$element][$type];
36
+			}
35 37
 			$element = $element->parentNode;
36 38
 		}
37 39
 		return $this->data;
Please login to merge, or discard this patch.
src/Parser/Tokenizer.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -105,7 +105,7 @@
 block discarded – undo
105 105
 			$string = $this->extractString($i);
106 106
 			$length = strlen($string)+1;
107 107
 			$char = $this->getChar($char);
108
-			$string = str_replace('\\' . $char, $char, $string);
108
+			$string = str_replace('\\'.$char, $char, $string);
109 109
 			$tokens[] = ['type' => self::STRING, 'value' => $string];
110 110
 			return $length;
111 111
 		}
Please login to merge, or discard this patch.
Braces   +25 added lines, -10 removed lines patch added patch discarded remove patch
@@ -81,10 +81,15 @@  discard block
 block discarded – undo
81 81
 	}
82 82
 
83 83
 	private function processLiterals(&$tokens, $name) {
84
-		if (is_numeric($name)) $tokens[] = ['type' => self::NUMERIC, 'value' => $name];
85
-		else if ($name == 'true') $tokens[] = ['type' => self::BOOL, 'value' => true];
86
-		else if ($name == 'false') $tokens[] = ['type' => self::BOOL, 'value' => false];
87
-		else $tokens[] = ['type' => self::NAME, 'value' => $name];
84
+		if (is_numeric($name)) {
85
+			$tokens[] = ['type' => self::NUMERIC, 'value' => $name];
86
+		} else if ($name == 'true') {
87
+			$tokens[] = ['type' => self::BOOL, 'value' => true];
88
+		} else if ($name == 'false') {
89
+			$tokens[] = ['type' => self::BOOL, 'value' => false];
90
+		} else {
91
+			$tokens[] = ['type' => self::NAME, 'value' => $name];
92
+		}
88 93
 	}
89 94
 
90 95
 	private function doBrackets(&$tokens, $char, $i) {
@@ -118,7 +123,9 @@  discard block
 block discarded – undo
118 123
 	private function extractString($pos) {
119 124
 		$char = $this->str[$pos];
120 125
 		$end = strpos($this->str, $char, $pos+1);
121
-		while ($end !== false && $this->str[$end-1] == '\\') $end = strpos($this->str, $char, $end+1);
126
+		while ($end !== false && $this->str[$end-1] == '\\') {
127
+			$end = strpos($this->str, $char, $end+1);
128
+		}
122 129
 
123 130
 		return substr($this->str, $pos+1, $end-$pos-1);
124 131
 	}
@@ -127,18 +134,26 @@  discard block
 block discarded – undo
127 134
 		$close = strpos($this->str, $closeBracket, $open);
128 135
 
129 136
 		$cPos = $open+1;
130
-		while (($cPos = strpos($this->str, $startBracket, $cPos+1)) !== false && $cPos < $close) $close = strpos($this->str, $closeBracket, $close+1);
137
+		while (($cPos = strpos($this->str, $startBracket, $cPos+1)) !== false && $cPos < $close) {
138
+			$close = strpos($this->str, $closeBracket, $close+1);
139
+		}
131 140
 		return substr($this->str, $open+1, $close-$open-1);
132 141
 	}
133 142
 
134 143
 	private function identifyChar($chr) {
135
-		if (isset($this->chars[$chr])) return $this->chars[$chr];
136
-		else return self::NAME;
144
+		if (isset($this->chars[$chr])) {
145
+			return $this->chars[$chr];
146
+		} else {
147
+			return self::NAME;
148
+		}
137 149
 	}
138 150
 
139 151
 	private function getChar($num) {
140 152
 		$chars = array_reverse($this->chars);
141
-		if (isset($chars[$num])) return $chars[$num];
142
-		else return false;
153
+		if (isset($chars[$num])) {
154
+			return $chars[$num];
155
+		} else {
156
+			return false;
157
+		}
143 158
 	}
144 159
 }
Please login to merge, or discard this patch.
src/Property/Display.php 1 patch
Braces   +7 added lines, -3 removed lines patch added patch discarded remove patch
@@ -7,8 +7,12 @@
 block discarded – undo
7 7
 namespace Transphporm\Property;
8 8
 class Display implements \Transphporm\Property {
9 9
 	public function run(array $values, \DomElement $element, array $rules, \Transphporm\Hook\PseudoMatcher $pseudoMatcher, array $properties = []) {
10
-		if ($pseudoMatcher->hasFunction('attr')) $element->removeAttribute($pseudoMatcher->getFuncArgs('attr'));
11
-		else if (strtolower($values[0]) === 'none') $element->setAttribute('transphporm', 'remove');
12
-		else $element->setAttribute('transphporm', 'show');
10
+		if ($pseudoMatcher->hasFunction('attr')) {
11
+			$element->removeAttribute($pseudoMatcher->getFuncArgs('attr'));
12
+		} else if (strtolower($values[0]) === 'none') {
13
+			$element->setAttribute('transphporm', 'remove');
14
+		} else {
15
+			$element->setAttribute('transphporm', 'show');
16
+		}
13 17
 	}
14 18
 }
15 19
\ No newline at end of file
Please login to merge, or discard this patch.
src/TSSFunction/Data.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@
 block discarded – undo
6 6
  * @version         1.0                                                             */
7 7
 namespace Transphporm\TSSFunction;
8 8
 /* Handles data() and iteration() function calls from the stylesheet */
9
-class Data implements \Transphporm\TSSFunction{
9
+class Data implements \Transphporm\TSSFunction {
10 10
 	private $data;
11 11
 	private $dataKey;
12 12
 	private $functionSet;
Please login to merge, or discard this patch.
Braces   +5 added lines, -2 removed lines patch added patch discarded remove patch
@@ -18,8 +18,11 @@
 block discarded – undo
18 18
 	}
19 19
 
20 20
 	public function run(array $args, \DomElement $element = null) {
21
-		if ($this->dataKey === "root") $data = $this->data->getData(null, 'data');
22
-		else $data = $this->data->getData($element, $this->dataKey);
21
+		if ($this->dataKey === "root") {
22
+			$data = $this->data->getData(null, 'data');
23
+		} else {
24
+			$data = $this->data->getData($element, $this->dataKey);
25
+		}
23 26
 		$parser = new \Transphporm\Parser\Value($this->functionSet, true);
24 27
 		$return = $parser->parseTokens($args, $data);
25 28
 		return $return[0];
Please login to merge, or discard this patch.