Completed
Push — master ( d2d04e...eac26a )
by Tom
03:16
created
src/Parser/StringExtractor.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -17,8 +17,8 @@
 block discarded – undo
17 17
 		while (($pos = strpos($str, '"', $pos+1)) !== false) {
18 18
 			$end = strpos($str, '"', $pos+1);
19 19
 			while ($str[$end-1] == '\\') $end = strpos($str, '"', $end+1);
20
-			$strings['$+STR' . ++$num] = substr($str, $pos, $end-$pos+1);
21
-			$str = substr_replace($str, '$+STR' . $num, $pos, $end-$pos+1);
20
+			$strings['$+STR'.++$num] = substr($str, $pos, $end-$pos+1);
21
+			$str = substr_replace($str, '$+STR'.$num, $pos, $end-$pos+1);
22 22
 		}
23 23
 
24 24
 		return [$str, $strings];
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -16,7 +16,9 @@
 block discarded – undo
16 16
 		$strings = [];
17 17
 		while (($pos = strpos($str, '"', $pos+1)) !== false) {
18 18
 			$end = strpos($str, '"', $pos+1);
19
-			while ($str[$end-1] == '\\') $end = strpos($str, '"', $end+1);
19
+			while ($str[$end-1] == '\\') {
20
+				$end = strpos($str, '"', $end+1);
21
+			}
20 22
 			$strings['$+STR' . ++$num] = substr($str, $pos, $end-$pos+1);
21 23
 			$str = substr_replace($str, '$+STR' . $num, $pos, $end-$pos+1);
22 24
 		}
Please login to merge, or discard this patch.
src/Parser/Value.php 3 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -64,7 +64,7 @@
 block discarded – undo
64 64
 		$finalPos = $this->findMatchingPos($str, $marker);
65 65
 		$string = substr($str, 1, $finalPos-1);
66 66
 		//Now remove escape characters
67
-		return str_replace('\\' . $marker, $marker, $string);
67
+		return str_replace('\\'.$marker, $marker, $string);
68 68
 	}
69 69
 
70 70
 	private function parseFunction($function) {
Please login to merge, or discard this patch.
Doc Comments   +7 added lines patch added patch discarded remove patch
@@ -63,6 +63,9 @@  discard block
 block discarded – undo
63 63
 		return $array;
64 64
 	}
65 65
 
66
+	/**
67
+	 * @param \DOMElement $element
68
+	 */
66 69
 	private function callFunc($name, $params, $element) {
67 70
 		if ($name && is_callable([$this->dataFunction, $name])) {
68 71
 			return $this->dataFunction->$name($this->parse($params, $element), $element);	
@@ -70,6 +73,10 @@  discard block
 block discarded – undo
70 73
 		return false;
71 74
 	}
72 75
 
76
+	/**
77
+	 * @param string $remaining
78
+	 * @param \DOMElement $element
79
+	 */
73 80
 	private function parseNextValue($remaining, $result, $element) {
74 81
 		if (strlen($remaining) > 0 && $remaining[0] == ',') $result = array_merge($result, $this->parse(trim(substr($remaining, 1)), $element));
75 82
 		return $result;
Please login to merge, or discard this patch.
Braces   +17 added lines, -10 removed lines patch added patch discarded remove patch
@@ -28,8 +28,9 @@  discard block
 block discarded – undo
28 28
 			$params = $bracketMatcher->match('(', ')');
29 29
 			
30 30
 			return ['name' => $name, 'params' => $params, 'endPoint' => $bracketMatcher->getClosePos()];
31
+		} else {
32
+			return ['name' => null, 'params' => $function, 'endPoint' => strlen($function)];
31 33
 		}
32
-		else return ['name' => null, 'params' => $function, 'endPoint' => strlen($function)];
33 34
 	}
34 35
 
35 36
 	public function parse($function, \DomElement $element) {
@@ -37,23 +38,26 @@  discard block
 block discarded – undo
37 38
 		if ($function && in_array($function[0], ['\'', '"'])) {
38 39
 			$finalPos = $this->findMatchingPos($function, $function[0]);
39 40
 			$result[] = $this->extractQuotedString($function[0], $function);
40
-		}
41
-		else {
41
+		} else {
42 42
 			$func = $this->parseFunction($function);
43 43
 			$finalPos = $func['endPoint'];			
44 44
 
45 45
 			if (($data = $this->callFunc($func['name'], $func['params'], $element)) !== false) {
46 46
 				$result = $this->appendToArray($result, $data);
47
-			} 
48
-			else $result[] = trim($function);
47
+			} else {
48
+				$result[] = trim($function);
49
+			}
49 50
 		}
50 51
 		$remaining = trim(substr($function, $finalPos+1));
51 52
 		return $this->parseNextValue($remaining, $result, $element);
52 53
 	}
53 54
 
54 55
 	private function appendToArray($array, $value) {
55
-		if (is_array($value)) $array += $value;
56
-		else $array[] = $value;
56
+		if (is_array($value)) {
57
+			$array += $value;
58
+		} else {
59
+			$array[] = $value;
60
+		}
57 61
 		return $array;
58 62
 	}
59 63
 
@@ -65,7 +69,9 @@  discard block
 block discarded – undo
65 69
 	}
66 70
 
67 71
 	private function parseNextValue($remaining, $result, $element) {
68
-		if (strlen($remaining) > 0 && $remaining[0] == ',') $result = array_merge($result, $this->parse(trim(substr($remaining, 1)), $element));
72
+		if (strlen($remaining) > 0 && $remaining[0] == ',') {
73
+			$result = array_merge($result, $this->parse(trim(substr($remaining, 1)), $element));
74
+		}
69 75
 		return $result;
70 76
 	}
71 77
 	
@@ -73,8 +79,9 @@  discard block
 block discarded – undo
73 79
 		$pos = $start+1;
74 80
 		$end = 0;
75 81
 		while ($end = strpos($string, $char, $pos)) {
76
-			if ($string[$end-1] === $escape) $pos = $end+1;
77
-			else {
82
+			if ($string[$end-1] === $escape) {
83
+				$pos = $end+1;
84
+			} else {
78 85
 				break;
79 86
 			}
80 87
 		}
Please login to merge, or discard this patch.
src/Parser/CssToXpath.php 3 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -50,6 +50,9 @@
 block discarded – undo
50 50
 		return $attr;
51 51
 	}
52 52
 
53
+	/**
54
+	 * @param string $comparator
55
+	 */
53 56
 	private static function compare($comparator, $a, $b) {
54 57
 		if ($comparator == '=') return $a == $b;
55 58
 		else if ($comparator == '!=') return $a != $b;
Please login to merge, or discard this patch.
Braces   +10 added lines, -4 removed lines patch added patch discarded remove patch
@@ -51,8 +51,11 @@  discard block
 block discarded – undo
51 51
 	}
52 52
 
53 53
 	private static function compare($comparator, $a, $b) {
54
-		if ($comparator == '=') return $a == $b;
55
-		else if ($comparator == '!=') return $a != $b;
54
+		if ($comparator == '=') {
55
+			return $a == $b;
56
+		} else if ($comparator == '!=') {
57
+			return $a != $b;
58
+		}
56 59
 	}
57 60
 
58 61
 	//split the css into indivudal functions
@@ -66,8 +69,9 @@  discard block
 block discarded – undo
66 69
 				$selector = $this->createSelector();
67 70
 				$selector->type = $css[$i];
68 71
 				$selectors[] = $selector;
72
+			} else {
73
+				$selector->string .= $css[$i];
69 74
 			}
70
-			else $selector->string .= $css[$i];			
71 75
 		}
72 76
 		return $selectors;
73 77
 	}
@@ -78,7 +82,9 @@  discard block
 block discarded – undo
78 82
 		$this->depth = count($selectors);
79 83
 		$xpath = '/';
80 84
 		foreach ($selectors as $selector) {
81
-			if (isset($this->translators[$selector->type])) $xpath .= $this->translators[$selector->type]($selector->string, $xpath);
85
+			if (isset($this->translators[$selector->type])) {
86
+				$xpath .= $this->translators[$selector->type]($selector->string, $xpath);
87
+			}
82 88
 		}
83 89
 
84 90
 		$xpath = str_replace('/[', '/*[', $xpath);
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -15,14 +15,14 @@
 block discarded – undo
15 15
 	public function __construct($css, Value $valueParser, $prefix = '') {
16 16
 		$hash = $this->registerInstance();
17 17
 		$this->valueParser = $valueParser;
18
-		$this->css = str_replace([' >', '> '],['>', '>'], trim($css));
18
+		$this->css = str_replace([' >', '> '], ['>', '>'], trim($css));
19 19
 		$this->translators = [
20
-			' ' => function($string) use ($prefix) { return '//' . $prefix . $string;	},
21
-			'' => function($string) use ($prefix) { return '/' . $prefix . $string;	},
22
-			'>' => function($string) use ($prefix) { return '/' . $prefix  . $string; },
23
-			'#' => function($string) { return '[@id=\'' . $string . '\']'; },
24
-			'.' => function($string) { return '[contains(concat(\' \', normalize-space(@class), \' \'), \' ' . $string . ' \')]'; }, 
25
-			'[' => function($string, $xpath) use($hash) { return '[' .'php:function(\'\Transphporm\Parser\CssToXpath::processAttr\', \'' . $string . '\', ., "' . $hash . '")' . ']';	},
20
+			' ' => function($string) use ($prefix) { return '//'.$prefix.$string; },
21
+			'' => function($string) use ($prefix) { return '/'.$prefix.$string; },
22
+			'>' => function($string) use ($prefix) { return '/'.$prefix.$string; },
23
+			'#' => function($string) { return '[@id=\''.$string.'\']'; },
24
+			'.' => function($string) { return '[contains(concat(\' \', normalize-space(@class), \' \'), \' '.$string.' \')]'; }, 
25
+			'[' => function($string, $xpath) use($hash) { return '['.'php:function(\'\Transphporm\Parser\CssToXpath::processAttr\', \''.$string.'\', ., "'.$hash.'")'.']'; },
26 26
 			']' => function() {	return ''; }
27 27
 		];
28 28
 	}
Please login to merge, or discard this patch.
src/Hook/PostProcess.php 1 patch
Braces   +7 added lines, -3 removed lines patch added patch discarded remove patch
@@ -9,9 +9,13 @@
 block discarded – undo
9 9
 class PostProcess implements \Transphporm\Hook {
10 10
 	public function run(\DomElement $element) {
11 11
 		$transphporm = $element->getAttribute('transphporm');
12
-		if ($transphporm === 'remove') $element->parentNode->removeChild($element);
13
-		else if ($transphporm === 'text') $element->parentNode->replaceChild($element->firstChild, $element);
14
-		else $element->removeAttribute('transphporm');
12
+		if ($transphporm === 'remove') {
13
+			$element->parentNode->removeChild($element);
14
+		} else if ($transphporm === 'text') {
15
+			$element->parentNode->replaceChild($element->firstChild, $element);
16
+		} else {
17
+			$element->removeAttribute('transphporm');
18
+		}
15 19
 	}
16 20
 
17 21
 }
18 22
\ No newline at end of file
Please login to merge, or discard this patch.
src/Parser/BracketMatcher.php 1 patch
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -19,7 +19,9 @@
 block discarded – undo
19 19
 		$close = strpos($this->str, $closingChr, $open);
20 20
 
21 21
 		$cPos = $open+1;
22
-		while (($cPos = strpos($this->str, $openChr, $cPos+1)) !== false && $cPos < $close) $close = strpos($this->str, $closingChr, $close+1);
22
+		while (($cPos = strpos($this->str, $openChr, $cPos+1)) !== false && $cPos < $close) {
23
+			$close = strpos($this->str, $closingChr, $close+1);
24
+		}
23 25
 
24 26
 		$this->startPos = $open;
25 27
 		$this->endPos = $close;
Please login to merge, or discard this patch.
src/Property/Content.php 2 patches
Doc Comments   +13 added lines patch added patch discarded remove patch
@@ -34,6 +34,10 @@  discard block
 block discarded – undo
34 34
 		return (isset($rules['content-mode'])) ? $rules['content-mode'] : 'append';
35 35
 	}
36 36
 
37
+	/**
38
+	 * @param \DOMElement $element
39
+	 * @param \Transphporm\Hook\PseudoMatcher $pseudoMatcher
40
+	 */
37 41
 	private function processPseudo($value, $element, $pseudoMatcher) {
38 42
 		$pseudoContent = ['attr', 'header', 'before', 'after'];
39 43
 		foreach ($pseudoContent as $pseudo) {
@@ -91,6 +95,9 @@  discard block
 block discarded – undo
91 95
 		foreach ($remove as $r) $r->parentNode->removeChild($r);
92 96
 	}
93 97
 
98
+	/**
99
+	 * @param \DOMElement $element
100
+	 */
94 101
 	private function replaceContent($element, $content) {
95 102
 		//If this rule was cached, the elements that were added last time need to be removed prior to running the rule again.
96 103
 		$this->removeAdded($element);
@@ -100,12 +107,18 @@  discard block
 block discarded – undo
100 107
 		$element->setAttribute('transphporm', 'remove');
101 108
 	}
102 109
 
110
+	/**
111
+	 * @param \DOMElement $element
112
+	 */
103 113
 	private function appendContent($element, $content) {
104 114
 		foreach ($this->getNode($content, $element->ownerDocument) as $node) {
105 115
 			$element->appendChild($node);
106 116
 		}
107 117
 	}
108 118
 	
119
+	/**
120
+	 * @param \DOMElement $element
121
+	 */
109 122
 	private function removeAllChildren($element) {
110 123
 		while ($element->hasChildNodes()) $element->removeChild($element->firstChild);
111 124
 	}
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($value, \DomElement $element, array $rules, \Transphporm\Hook\PseudoMatcher $pseudoMatcher, array $properties = []) {
21
-		if ($element->getAttribute('transphporm') === 'remove') return;
21
+		if ($element->getAttribute('transphporm') === 'remove') {
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
 
@@ -50,9 +55,10 @@  discard block
 block discarded – undo
50 55
 			if ($n instanceof \DomElement) {
51 56
 				$new = $document->importNode($n, true);
52 57
 				$new->setAttribute('transphporm', 'added');
53
-			}
54
-			else {
55
-				if ($n instanceof \DomText) $n = $n->nodeValue;
58
+			} else {
59
+				if ($n instanceof \DomText) {
60
+					$n = $n->nodeValue;
61
+				}
56 62
 				$new = $document->createElement('text');
57 63
 				$new->appendChild($document->createTextNode($n));
58 64
 				$new->setAttribute('transphporm', 'text');
@@ -88,7 +94,9 @@  discard block
 block discarded – undo
88 94
 		while ($e = $e->previousSibling && !in_array($e->getAttribute('transphporm'), [null, 'remove'])) {
89 95
 			$remove[] = $e;
90 96
 		}
91
-		foreach ($remove as $r) $r->parentNode->removeChild($r);
97
+		foreach ($remove as $r) {
98
+			$r->parentNode->removeChild($r);
99
+		}
92 100
 	}
93 101
 
94 102
 	private function replaceContent($element, $content) {
@@ -107,6 +115,8 @@  discard block
 block discarded – undo
107 115
 	}
108 116
 	
109 117
 	private function removeAllChildren($element) {
110
-		while ($element->hasChildNodes()) $element->removeChild($element->firstChild);
118
+		while ($element->hasChildNodes()) {
119
+			$element->removeChild($element->firstChild);
120
+		}
111 121
 	}
112 122
 }
113 123
\ No newline at end of file
Please login to merge, or discard this patch.
src/Property/Repeat.php 2 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -34,6 +34,9 @@
 block discarded – undo
34 34
 		return false;
35 35
 	}
36 36
 
37
+	/**
38
+	 * @param \Transphporm\Hook\PseudoMatcher $pseudoMatcher
39
+	 */
37 40
 	private function createHook($newRules, $pseudoMatcher, $properties) {
38 41
 		$hook = new \Transphporm\Hook\PropertyHook($newRules, $pseudoMatcher, new \Transphporm\Parser\Value($this->data));
39 42
 		foreach ($properties as $name => $property) $hook->registerProperty($name, $property);
Please login to merge, or discard this patch.
Braces   +6 added lines, -2 removed lines patch added patch discarded remove patch
@@ -13,7 +13,9 @@  discard block
 block discarded – undo
13 13
 	}
14 14
 
15 15
 	public function run($value, \DomElement $element, array $rules, \Transphporm\Hook\PseudoMatcher $pseudoMatcher, array $properties = []) {
16
-		if ($element->getAttribute('transphporm') === 'added') return $element->parentNode->removeChild($element);
16
+		if ($element->getAttribute('transphporm') === 'added') {
17
+			return $element->parentNode->removeChild($element);
18
+		}
17 19
 
18 20
 		foreach ($value as $key => $iteration) {
19 21
 			$clone = $element->cloneNode(true);
@@ -36,7 +38,9 @@  discard block
 block discarded – undo
36 38
 
37 39
 	private function createHook($newRules, $pseudoMatcher, $properties) {
38 40
 		$hook = new \Transphporm\Hook\PropertyHook($newRules, $pseudoMatcher, new \Transphporm\Parser\Value($this->data));
39
-		foreach ($properties as $name => $property) $hook->registerProperty($name, $property);
41
+		foreach ($properties as $name => $property) {
42
+			$hook->registerProperty($name, $property);
43
+		}
40 44
 		return $hook;
41 45
 	}
42 46
 }
43 47
\ No newline at end of file
Please login to merge, or discard this patch.
src/Hook/PropertyHook.php 1 patch
Braces   +9 added lines, -3 removed lines patch added patch discarded remove patch
@@ -20,11 +20,15 @@  discard block
 block discarded – undo
20 20
 
21 21
 	public function run(\DomElement $element) {	
22 22
 		//Don't run if there's a pseudo element like nth-child() and this element doesn't match it
23
-		if (!$this->pseudoMatcher->matches($element)) return;
23
+		if (!$this->pseudoMatcher->matches($element)) {
24
+			return;
25
+		}
24 26
 
25 27
 		foreach ($this->rules as $name => $value) {
26 28
 			$result = $this->callProperty($name, $element, $this->valueParser->parse(trim($value), $element));
27
-			if ($result === false) break;
29
+			if ($result === false) {
30
+				break;
31
+			}
28 32
 		}
29 33
 	}
30 34
 
@@ -45,7 +49,9 @@  discard block
 block discarded – undo
45 49
 	}
46 50
 
47 51
 	private function callProperty($name, $element, $value) {
48
-		if (isset($this->properties[$name])) return $this->properties[$name]->run($value, $element, $this->rules, $this->pseudoMatcher, $this->properties);
52
+		if (isset($this->properties[$name])) {
53
+			return $this->properties[$name]->run($value, $element, $this->rules, $this->pseudoMatcher, $this->properties);
54
+		}
49 55
 		return false;
50 56
 	}
51 57
 }
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($value, \DomElement $element, array $rules, \Transphporm\Hook\PseudoMatcher $pseudoMatcher, array $properties = []) {
10
-		if ($pseudoMatcher->hasFunction('attr')) $element->removeAttribute($pseudoMatcher->getFuncArgs('attr'));
11
-		else if (strtolower($value[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($value[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.