Completed
Push — master ( 247d83...132dc2 )
by Tom
02:31
created
src/Config.php 2 patches
Doc Comments   +9 added lines patch added patch discarded remove patch
@@ -13,6 +13,9 @@  discard block
 block discarded – undo
13 13
 	private $formatter; 
14 14
 	private $baseDir;
15 15
 	
16
+	/**
17
+	 * @param string $baseDir
18
+	 */
16 19
 	public function __construct(Functionset $functionSet, Hook\ElementData $elementData, Hook\Formatter $formatter, &$headers, &$baseDir) {
17 20
 		$this->formatter = $formatter;
18 21
 		$this->headers = &$headers;
@@ -41,10 +44,16 @@  discard block
 block discarded – undo
41 44
 		return $this->functionSet;
42 45
 	}
43 46
 
47
+	/**
48
+	 * @return Hook\ElementData
49
+	 */
44 50
 	public function getElementData() {
45 51
 		return $this->elementData;
46 52
 	}
47 53
 
54
+	/**
55
+	 * @param string $name
56
+	 */
48 57
 	public function registerProperty($name, Property $property) {
49 58
 		$this->properties[$name] = $property;
50 59
 	}
Please login to merge, or discard this patch.
Braces   +6 added lines, -2 removed lines patch added patch discarded remove patch
@@ -35,12 +35,16 @@
 block discarded – undo
35 35
 	}
36 36
 
37 37
 	public function loadProperties(Hook\PropertyHook $hook) {
38
-		foreach ($this->properties as $name => $property) $hook->registerProperty($name, $property);
38
+		foreach ($this->properties as $name => $property) {
39
+			$hook->registerProperty($name, $property);
40
+		}
39 41
 	}
40 42
 
41 43
 	public function createPseudoMatcher($pseudo) {
42 44
 		$pseudoMatcher = new Hook\PseudoMatcher($pseudo);
43
-		foreach ($this->pseudo as $pseudoFunction) $pseudoMatcher->registerFunction($pseudoFunction);
45
+		foreach ($this->pseudo as $pseudoFunction) {
46
+			$pseudoMatcher->registerFunction($pseudoFunction);
47
+		}
44 48
 		return $pseudoMatcher;
45 49
 	}
46 50
 }
47 51
\ No newline at end of file
Please login to merge, or discard this patch.
src/FunctionSet.php 2 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(Hook\ElementData $elementData, &$baseDir) {
15 18
 		$this->baseDir = &$baseDir;
16 19
 		$this->elementData = $elementData;
@@ -23,6 +26,9 @@  discard block
 block discarded – undo
23 26
 		else return \Transphporm\Parser\Value::IS_NOT_FUNCTION;
24 27
 	}
25 28
 
29
+	/**
30
+	 * @param string $name
31
+	 */
26 32
 	public function addFunction($name, \Transphporm\TSSFunction $function) {
27 33
 		$this->functions[$name] = $function;
28 34
 	}
Please login to merge, or discard this 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/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   +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/Data.php 3 patches
Doc Comments   +6 added lines patch added patch discarded remove patch
@@ -17,6 +17,9 @@  discard block
 block discarded – undo
17 17
 		$this->functionSet = $functionSet;
18 18
 	}
19 19
 
20
+	/**
21
+	 * @param \DOMElement $element
22
+	 */
20 23
 	private function traverse($name, $data, $element) {
21 24
 		$name = str_replace(['[', ']'], ['.', ''], $name);
22 25
 		$parts = explode('.', $name);
@@ -37,6 +40,9 @@  discard block
 block discarded – undo
37 40
 		return $obj;
38 41
 	}
39 42
 
43
+	/**
44
+	 * @param \Transphporm\Parser\Value $valueParser
45
+	 */
40 46
 	private function traverseObj($part, $obj, $valueParser, $element) {
41 47
 		if (strpos($part, '(') !== false) {
42 48
 			$subObjParser = new \Transphporm\Parser\Value($obj, $valueParser, false);
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -6,12 +6,12 @@
 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 $dataType;
12 12
 	private $functionSet;
13 13
 
14
-	public function __construct(\Transphporm\Hook\ElementData $data,  \Transphporm\FunctionSet $functionSet, $dataKey = 'data') {
14
+	public function __construct(\Transphporm\Hook\ElementData $data, \Transphporm\FunctionSet $functionSet, $dataKey = 'data') {
15 15
 		$this->data = $data;
16 16
 		$this->dataKey = $dataKey;
17 17
 		$this->functionSet = $functionSet;
Please login to merge, or discard this 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/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/TSSFunction/Template.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -22,9 +22,9 @@
 block discarded – undo
22 22
 
23 23
 	public function run(array $args, \DomElement $element) {
24 24
 		$selector = $this->readArray($args, 1);
25
-		$tss = $this->baseDir . $this->readArray($args, 2);
25
+		$tss = $this->baseDir.$this->readArray($args, 2);
26 26
 		
27
-		$newTemplate = new \Transphporm\Builder($this->baseDir . $args[0], $tss);
27
+		$newTemplate = new \Transphporm\Builder($this->baseDir.$args[0], $tss);
28 28
 
29 29
 		$doc = $newTemplate->output($this->elementData->getData($element), true)->body;
30 30
 		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
@@ -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.