@@ -11,6 +11,9 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 | } |
@@ -18,15 +18,20 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 | } |
@@ -18,6 +18,9 @@ |
||
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); |
@@ -27,6 +27,6 @@ |
||
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 |
@@ -22,7 +22,7 @@ |
||
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); |
@@ -30,7 +30,9 @@ discard block |
||
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 |
||
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 | } |
@@ -31,7 +31,9 @@ |
||
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; |
@@ -105,7 +105,7 @@ |
||
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 | } |
@@ -81,10 +81,15 @@ discard block |
||
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 |
||
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 |
||
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 | } |
@@ -6,7 +6,7 @@ |
||
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; |
@@ -18,8 +18,11 @@ |
||
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]; |
@@ -31,6 +31,9 @@ discard block |
||
31 | 31 | } |
32 | 32 | } |
33 | 33 | |
34 | + /** |
|
35 | + * @param \DOMElement $element |
|
36 | + */ |
|
34 | 37 | private function getArgs($value, $element) { |
35 | 38 | return $this->valueParser->parse($value, $element); |
36 | 39 | } |
@@ -39,6 +42,9 @@ discard block |
||
39 | 42 | $this->properties[$name] = $property; |
40 | 43 | } |
41 | 44 | |
45 | + /** |
|
46 | + * @param \DOMElement $element |
|
47 | + */ |
|
42 | 48 | private function callProperty($name, $element, $value) { |
43 | 49 | if (isset($this->properties[$name])) return $this->properties[$name]->run($value, $element, $this->rules, $this->pseudoMatcher, $this->properties); |
44 | 50 | return false; |
@@ -23,11 +23,15 @@ discard block |
||
23 | 23 | public function run(\DomElement $element) { |
24 | 24 | $this->functionSet->setElement($element); |
25 | 25 | //Don't run if there's a pseudo element like nth-child() and this element doesn't match it |
26 | - if (!$this->pseudoMatcher->matches($element)) return; |
|
26 | + if (!$this->pseudoMatcher->matches($element)) { |
|
27 | + return; |
|
28 | + } |
|
27 | 29 | |
28 | 30 | foreach ($this->rules as $name => $value) { |
29 | 31 | $result = $this->callProperty($name, $element, $this->getArgs($value, $element)); |
30 | - if ($result === false) break; |
|
32 | + if ($result === false) { |
|
33 | + break; |
|
34 | + } |
|
31 | 35 | } |
32 | 36 | } |
33 | 37 | |
@@ -40,8 +44,12 @@ discard block |
||
40 | 44 | } |
41 | 45 | |
42 | 46 | private function callProperty($name, $element, $value) { |
43 | - if (empty($value[0])) $value[0] = []; |
|
44 | - if (isset($this->properties[$name])) return $this->properties[$name]->run($value, $element, $this->rules, $this->pseudoMatcher, $this->properties); |
|
47 | + if (empty($value[0])) { |
|
48 | + $value[0] = []; |
|
49 | + } |
|
50 | + if (isset($this->properties[$name])) { |
|
51 | + return $this->properties[$name]->run($value, $element, $this->rules, $this->pseudoMatcher, $this->properties); |
|
52 | + } |
|
45 | 53 | return false; |
46 | 54 | } |
47 | 55 | } |
@@ -1,25 +1,25 @@ |
||
1 | 1 | <?php |
2 | 2 | namespace Transphporm\TSSFunction; |
3 | 3 | class Json implements \Transphporm\TSSFunction { |
4 | - private $baseDir; |
|
4 | + private $baseDir; |
|
5 | 5 | |
6 | - public function __construct(&$baseDir) { |
|
7 | - $this->baseDir = &$baseDir; |
|
8 | - } |
|
6 | + public function __construct(&$baseDir) { |
|
7 | + $this->baseDir = &$baseDir; |
|
8 | + } |
|
9 | 9 | |
10 | - public function run(array $args, \DomElement $element = null) { |
|
11 | - $json = $args[0]; |
|
10 | + public function run(array $args, \DomElement $element = null) { |
|
11 | + $json = $args[0]; |
|
12 | 12 | |
13 | - if (trim($json)[0] != '{') { |
|
14 | - $path = $this->baseDir . $json; |
|
15 | - if (!file_exists($path)) throw new \Exception('File does not exist at: ' . $path); |
|
16 | - $json = file_get_contents($json); |
|
17 | - } |
|
13 | + if (trim($json)[0] != '{') { |
|
14 | + $path = $this->baseDir . $json; |
|
15 | + if (!file_exists($path)) throw new \Exception('File does not exist at: ' . $path); |
|
16 | + $json = file_get_contents($json); |
|
17 | + } |
|
18 | 18 | |
19 | - $map = json_decode($json, true); |
|
19 | + $map = json_decode($json, true); |
|
20 | 20 | |
21 | - if (!is_array($map)) throw new \Exception('Could not decode json: ' . json_last_error_msg()); |
|
21 | + if (!is_array($map)) throw new \Exception('Could not decode json: ' . json_last_error_msg()); |
|
22 | 22 | |
23 | - return $map; |
|
24 | - } |
|
23 | + return $map; |
|
24 | + } |
|
25 | 25 | } |
@@ -11,14 +11,14 @@ |
||
11 | 11 | $json = $args[0]; |
12 | 12 | |
13 | 13 | if (trim($json)[0] != '{') { |
14 | - $path = $this->baseDir . $json; |
|
15 | - if (!file_exists($path)) throw new \Exception('File does not exist at: ' . $path); |
|
14 | + $path = $this->baseDir.$json; |
|
15 | + if (!file_exists($path)) throw new \Exception('File does not exist at: '.$path); |
|
16 | 16 | $json = file_get_contents($json); |
17 | 17 | } |
18 | 18 | |
19 | 19 | $map = json_decode($json, true); |
20 | 20 | |
21 | - if (!is_array($map)) throw new \Exception('Could not decode json: ' . json_last_error_msg()); |
|
21 | + if (!is_array($map)) throw new \Exception('Could not decode json: '.json_last_error_msg()); |
|
22 | 22 | |
23 | 23 | return $map; |
24 | 24 | } |
@@ -12,13 +12,17 @@ |
||
12 | 12 | |
13 | 13 | if (trim($json)[0] != '{') { |
14 | 14 | $path = $this->baseDir . $json; |
15 | - if (!file_exists($path)) throw new \Exception('File does not exist at: ' . $path); |
|
15 | + if (!file_exists($path)) { |
|
16 | + throw new \Exception('File does not exist at: ' . $path); |
|
17 | + } |
|
16 | 18 | $json = file_get_contents($json); |
17 | 19 | } |
18 | 20 | |
19 | 21 | $map = json_decode($json, true); |
20 | 22 | |
21 | - if (!is_array($map)) throw new \Exception('Could not decode json: ' . json_last_error_msg()); |
|
23 | + if (!is_array($map)) { |
|
24 | + throw new \Exception('Could not decode json: ' . json_last_error_msg()); |
|
25 | + } |
|
22 | 26 | |
23 | 27 | return $map; |
24 | 28 | } |
@@ -67,12 +67,16 @@ |
||
67 | 67 | } |
68 | 68 | |
69 | 69 | public function loadProperties(Hook\PropertyHook $hook) { |
70 | - foreach ($this->properties as $name => $property) $hook->registerProperty($name, $property); |
|
70 | + foreach ($this->properties as $name => $property) { |
|
71 | + $hook->registerProperty($name, $property); |
|
72 | + } |
|
71 | 73 | } |
72 | 74 | |
73 | 75 | public function createPseudoMatcher($pseudo) { |
74 | 76 | $pseudoMatcher = new Hook\PseudoMatcher($pseudo); |
75 | - foreach ($this->pseudo as $pseudoFunction) $pseudoMatcher->registerFunction($pseudoFunction); |
|
77 | + foreach ($this->pseudo as $pseudoFunction) { |
|
78 | + $pseudoMatcher->registerFunction($pseudoFunction); |
|
79 | + } |
|
76 | 80 | return $pseudoMatcher; |
77 | 81 | } |
78 | 82 |