Completed
Push — master ( 653716...26bcfc )
by Tom
02:35
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/Hook/DataFunction.php 3 patches
Doc Comments   +7 added lines patch added patch discarded remove patch
@@ -11,6 +11,10 @@  discard block
 block discarded – undo
11 11
 	private $data;
12 12
 	private $baseDir;
13 13
 
14
+	/**
15
+	 * @param string $baseDir
16
+	 * @param string $tss
17
+	 */
14 18
 	public function __construct(\SplObjectStorage $objectStorage, $data, $baseDir, $tss) {
15 19
 		$this->dataStorage = $objectStorage;
16 20
 		$this->data = $data;
@@ -75,6 +79,9 @@  discard block
 block discarded – undo
75 79
 		return $obj;
76 80
 	}
77 81
 
82
+	/**
83
+	 * @param \Transphporm\Parser\Value $valueParser
84
+	 */
78 85
 	private function traverseObj($part, $obj, $valueParser, $element) {
79 86
 		if (strpos($part, '(') !== false) {
80 87
 			$subObjParser = new \Transphporm\Parser\Value($obj, $valueParser, false);
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -107,7 +107,7 @@
 block discarded – undo
107 107
 	}
108 108
 
109 109
 	public function template($val, $element) {
110
-		$newTemplate = new \Transphporm\Builder($this->baseDir . $val[0], $this->tss);
110
+		$newTemplate = new \Transphporm\Builder($this->baseDir.$val[0], $this->tss);
111 111
 		$data = $this->getData($element);
112 112
 
113 113
 		$doc = $newTemplate->output($data, true)->body;
Please login to merge, or discard this patch.
Braces   +29 added lines, -12 removed lines patch added patch discarded remove patch
@@ -21,7 +21,9 @@  discard block
 block discarded – undo
21 21
 	/** Binds data to an element */
22 22
 	public function bind(\DomNode $element, $data, $type = 'data') {
23 23
 		//This is a bit of a hack to workaround #24, might need a better way of doing this if it causes a problem
24
-		if (is_array($data) && $this->isObjectArray($data)) $data = $data[0];
24
+		if (is_array($data) && $this->isObjectArray($data)) {
25
+			$data = $data[0];
26
+		}
25 27
 		$content = isset($this->dataStorage[$element]) ? $this->dataStorage[$element] : [];
26 28
 		$content[$type] = $data;
27 29
 		$this->dataStorage[$element] = $content;
@@ -45,7 +47,9 @@  discard block
 block discarded – undo
45 47
 	/** 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*/
46 48
 	public function getData(\DomElement $element = null, $type = 'data') {
47 49
 		while ($element) {
48
-			if (isset($this->dataStorage[$element]) && isset($this->dataStorage[$element][$type])) return $this->dataStorage[$element][$type];
50
+			if (isset($this->dataStorage[$element]) && isset($this->dataStorage[$element][$type])) {
51
+				return $this->dataStorage[$element][$type];
52
+			}
49 53
 			$element = $element->parentNode;
50 54
 		}
51 55
 		return $this->data;
@@ -64,13 +68,17 @@  discard block
 block discarded – undo
64 68
 		$valueParser = new \Transphporm\Parser\Value($this);
65 69
 
66 70
 		foreach ($parts as $part) {
67
-			if ($part === '') continue;
71
+			if ($part === '') {
72
+				continue;
73
+			}
68 74
 			$part = $valueParser->parse($part, $element)[0];
69 75
 			$funcResult = $this->traverseObj($part, $obj, $valueParser, $element);
70 76
 			
71
-			if ($funcResult !== false) $obj = $funcResult;
72
-			
73
-			else $obj = $this->ifNull($obj, $part);
77
+			if ($funcResult !== false) {
78
+				$obj = $funcResult;
79
+			} else {
80
+				$obj = $this->ifNull($obj, $part);
81
+			}
74 82
 		}
75 83
 		return $obj;
76 84
 	}
@@ -79,14 +87,19 @@  discard block
 block discarded – undo
79 87
 		if (strpos($part, '(') !== false) {
80 88
 			$subObjParser = new \Transphporm\Parser\Value($obj, $valueParser, false);
81 89
 			return $subObjParser->parse($part, $element);
90
+		} else if (method_exists($obj, $part)) {
91
+			return call_user_func([$obj, $part]);
92
+		} else {
93
+			return false;
82 94
 		}
83
-		else if (method_exists($obj, $part)) return call_user_func([$obj, $part]); 
84
-		else return false;
85 95
 	}
86 96
 
87 97
 	private function ifNull($obj, $key) {
88
-		if (is_array($obj)) return isset($obj[$key]) ? $obj[$key] : null;
89
-		else return isset($obj->$key) ? $obj->$key : null;
98
+		if (is_array($obj)) {
99
+			return isset($obj[$key]) ? $obj[$key] : null;
100
+		} else {
101
+			return isset($obj->$key) ? $obj->$key : null;
102
+		}
90 103
 	}
91 104
 
92 105
 	public function attr($val, $element) {
@@ -112,7 +125,9 @@  discard block
 block discarded – undo
112 125
 
113 126
 		$doc = $newTemplate->output($data, true)->body;
114 127
 
115
-		if (isset($val[1])) return $this->templateSubsection($val[1], $doc, $element);
128
+		if (isset($val[1])) {
129
+			return $this->templateSubsection($val[1], $doc, $element);
130
+		}
116 131
 		
117 132
 		$newNode = $element->ownerDocument->importNode($doc->documentElement, true);
118 133
 	//	$this->bind($newNode, $data);
@@ -121,7 +136,9 @@  discard block
 block discarded – undo
121 136
 		if ($newNode->tagName === 'template') {
122 137
 			foreach ($newNode->childNodes as $node) {
123 138
 				$clone = $node->cloneNode(true);
124
-				if ($clone instanceof \DomElement) $clone->setAttribute('transphporm', 'includedtemplate');
139
+				if ($clone instanceof \DomElement) {
140
+					$clone->setAttribute('transphporm', 'includedtemplate');
141
+				}
125 142
 				$result[] = $clone;
126 143
 			}
127 144
 		}		
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\Hook\DataFunction $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
 
@@ -44,6 +50,10 @@  discard block
 block discarded – undo
44 50
 		return (isset($rules['content-mode'])) ? $rules['content-mode'] : 'append';
45 51
 	}
46 52
 
53
+	/**
54
+	 * @param \DOMElement $element
55
+	 * @param \Transphporm\Hook\PseudoMatcher $pseudoMatcher
56
+	 */
47 57
 	private function processPseudo($value, $element, $pseudoMatcher) {
48 58
 		$pseudoContent = ['attr', 'header', 'before', 'after'];
49 59
 		foreach ($pseudoContent as $pseudo) {
@@ -101,6 +111,9 @@  discard block
 block discarded – undo
101 111
 		foreach ($remove as $r) $r->parentNode->removeChild($r);
102 112
 	}
103 113
 
114
+	/**
115
+	 * @param \DOMElement $element
116
+	 */
104 117
 	private function replaceContent($element, $content) {
105 118
 		//If this rule was cached, the elements that were added last time need to be removed prior to running the rule again.
106 119
 		$this->removeAdded($element);
@@ -110,12 +123,18 @@  discard block
 block discarded – undo
110 123
 		$element->setAttribute('transphporm', 'remove');
111 124
 	}
112 125
 
126
+	/**
127
+	 * @param \DOMElement $element
128
+	 */
113 129
 	private function appendContent($element, $content) {
114 130
 		foreach ($this->getNode($content, $element->ownerDocument) as $node) {
115 131
 			$element->appendChild($node);
116 132
 		}
117 133
 	}
118 134
 	
135
+	/**
136
+	 * @param \DOMElement $element
137
+	 */
119 138
 	private function removeAllChildren($element) {
120 139
 		while ($element->hasChildNodes()) $element->removeChild($element->firstChild);
121 140
 	}
Please login to merge, or discard this patch.
Braces   +27 added lines, -11 removed lines patch added patch discarded remove patch
@@ -18,23 +18,34 @@  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->isIncludedTemplate($element)) return;
22
-		if ($element->getAttribute('transphporm') === 'remove') return;
21
+		if ($this->isIncludedTemplate($element)) {
22
+			return;
23
+		}
24
+		if ($element->getAttribute('transphporm') === 'remove') {
25
+			return;
26
+		}
23 27
 	
24 28
 		$value = $this->formatter->format($value, $rules);
25 29
 		if (!$this->processPseudo($value, $element, $pseudoMatcher)) {
26 30
 			//Remove the current contents
27 31
 			$this->removeAllChildren($element);
28 32
 			//Now make a text node
29
-			if ($this->getContentMode($rules) === 'replace') $this->replaceContent($element, $value);
30
-			else $this->appendContent($element, $value);
33
+			if ($this->getContentMode($rules) === 'replace') {
34
+				$this->replaceContent($element, $value);
35
+			} else {
36
+				$this->appendContent($element, $value);
37
+			}
31 38
 		}
32 39
 	}
33 40
 
34 41
 	private function isIncludedTemplate($element) {
35 42
 		do {
36
-			if ($element instanceof \DomDocument) return false;
37
-			if ($element->getAttribute('transphporm') == 'includedtemplate') return true;
43
+			if ($element instanceof \DomDocument) {
44
+				return false;
45
+			}
46
+			if ($element->getAttribute('transphporm') == 'includedtemplate') {
47
+				return true;
48
+			}
38 49
 		}
39 50
 		while ($element = $element->parentNode);
40 51
 		return false;
@@ -60,9 +71,10 @@  discard block
 block discarded – undo
60 71
 				$new = $document->importNode($n, true);
61 72
 				//Removing this might cause problems with caching... 
62 73
 				//$new->setAttribute('transphporm', 'added');
63
-			}
64
-			else {
65
-				if ($n instanceof \DomText) $n = $n->nodeValue;
74
+			} else {
75
+				if ($n instanceof \DomText) {
76
+					$n = $n->nodeValue;
77
+				}
66 78
 				$new = $document->createElement('text');
67 79
 				$new->appendChild($document->createTextNode($n));
68 80
 				$new->setAttribute('transphporm', 'text');
@@ -98,7 +110,9 @@  discard block
 block discarded – undo
98 110
 		while ($e = $e->previousSibling && !in_array($e->getAttribute('transphporm'), [null, 'remove'])) {
99 111
 			$remove[] = $e;
100 112
 		}
101
-		foreach ($remove as $r) $r->parentNode->removeChild($r);
113
+		foreach ($remove as $r) {
114
+			$r->parentNode->removeChild($r);
115
+		}
102 116
 	}
103 117
 
104 118
 	private function replaceContent($element, $content) {
@@ -117,6 +131,8 @@  discard block
 block discarded – undo
117 131
 	}
118 132
 	
119 133
 	private function removeAllChildren($element) {
120
-		while ($element->hasChildNodes()) $element->removeChild($element->firstChild);
134
+		while ($element->hasChildNodes()) {
135
+			$element->removeChild($element->firstChild);
136
+		}
121 137
 	}
122 138
 }
123 139
\ No newline at end of file
Please login to merge, or discard this patch.