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