@@ -18,12 +18,16 @@ discard block |
||
18 | 18 | |
19 | 19 | public function run(array $values, \DomElement $element, array $rules, \Transphporm\Hook\PseudoMatcher $pseudoMatcher, array $properties = []) { |
20 | 20 | $values = $this->fixEmpty($values); |
21 | - if ($element->getAttribute('transphporm') === 'added') return $element->parentNode->removeChild($element); |
|
21 | + if ($element->getAttribute('transphporm') === 'added') { |
|
22 | + return $element->parentNode->removeChild($element); |
|
23 | + } |
|
22 | 24 | $max = $this->getMax($values); |
23 | 25 | $count = 0; |
24 | 26 | |
25 | 27 | foreach ($values[0] as $key => $iteration) { |
26 | - if ($count+1 > $max) break; |
|
28 | + if ($count+1 > $max) { |
|
29 | + break; |
|
30 | + } |
|
27 | 31 | $clone = $this->cloneElement($element, $iteration, $key, $count++); |
28 | 32 | //Re-run the hook on the new element, but use the iterated data |
29 | 33 | //Don't run repeat on the clones element or it will loop forever |
@@ -36,7 +40,9 @@ discard block |
||
36 | 40 | } |
37 | 41 | |
38 | 42 | private function fixEmpty($value) { |
39 | - if (empty($value[0])) $value[0] = []; |
|
43 | + if (empty($value[0])) { |
|
44 | + $value[0] = []; |
|
45 | + } |
|
40 | 46 | return $value; |
41 | 47 | } |
42 | 48 | |
@@ -52,7 +58,9 @@ discard block |
||
52 | 58 | |
53 | 59 | private function tagElement($element, $count) { |
54 | 60 | //Mark all but one of the nodes as having been added by transphporm, when the hook is run again, these are removed |
55 | - if ($count > 0) $element->setAttribute('transphporm', 'added'); |
|
61 | + if ($count > 0) { |
|
62 | + $element->setAttribute('transphporm', 'added'); |
|
63 | + } |
|
56 | 64 | } |
57 | 65 | |
58 | 66 | private function getMax($values) { |
@@ -61,7 +69,9 @@ discard block |
||
61 | 69 | |
62 | 70 | private function createHook($newRules, $pseudoMatcher, $properties) { |
63 | 71 | $hook = new \Transphporm\Hook\PropertyHook($newRules, $this->baseDir, $this->baseDir, $pseudoMatcher, new \Transphporm\Parser\Value($this->functionSet), $this->functionSet); |
64 | - foreach ($properties as $name => $property) $hook->registerProperty($name, $property); |
|
72 | + foreach ($properties as $name => $property) { |
|
73 | + $hook->registerProperty($name, $property); |
|
74 | + } |
|
65 | 75 | return $hook; |
66 | 76 | } |
67 | 77 | } |
@@ -49,7 +49,9 @@ discard block |
||
49 | 49 | $this->data = new ValueData($data ? $data : $this->baseData); |
50 | 50 | $this->last = null; |
51 | 51 | |
52 | - if (count($tokens) <= 0) return [$data]; |
|
52 | + if (count($tokens) <= 0) { |
|
53 | + return [$data]; |
|
54 | + } |
|
53 | 55 | |
54 | 56 | foreach (new TokenFilterIterator($tokens, [Tokenizer::WHITESPACE]) as $token) { |
55 | 57 | $this->{$this->tokenFuncs[$token['type']]}($token); |
@@ -71,13 +73,15 @@ discard block |
||
71 | 73 | //Reads the last selected value from $data regardless if it's an array or object and overrides $this->data with the new value |
72 | 74 | //Dot moves $data to the next object in $data foo.bar moves the $data pointer from `foo` to `bar` |
73 | 75 | private function processDot($token) { |
74 | - if ($this->last !== null) $this->data->traverse($this->last); |
|
75 | - else { |
|
76 | + if ($this->last !== null) { |
|
77 | + $this->data->traverse($this->last); |
|
78 | + } else { |
|
76 | 79 | //When . is not preceeded by anything, treat it as part of the string instead of an operator |
77 | 80 | // foo.bar is treated as looking up `bar` in `foo` whereas .foo is treated as the string ".foo" |
78 | 81 | $lastResult = $this->result->pop(); |
79 | - if ($lastResult) $this->data = new ValueData($lastResult); |
|
80 | - else { |
|
82 | + if ($lastResult) { |
|
83 | + $this->data = new ValueData($lastResult); |
|
84 | + } else { |
|
81 | 85 | $this->processString(['value' => '.']); |
82 | 86 | $this->result->setMode(Tokenizer::CONCAT); |
83 | 87 | } |
@@ -90,9 +94,10 @@ discard block |
||
90 | 94 | $parser = new Value($this->baseData, $this->autoLookup); |
91 | 95 | if ($this->baseData instanceof \Transphporm\Functionset && $this->baseData->hasFunction($this->last)) { |
92 | 96 | $this->callTransphpormFunctions($token); |
93 | - } |
|
94 | - else { |
|
95 | - if ($this->last !== null) $this->data->traverse($this->last); |
|
97 | + } else { |
|
98 | + if ($this->last !== null) { |
|
99 | + $this->data->traverse($this->last); |
|
100 | + } |
|
96 | 101 | $this->last = $parser->parseTokens($token['value'], null)[0]; |
97 | 102 | } |
98 | 103 | } |
@@ -112,8 +117,7 @@ discard block |
||
112 | 117 | private function processBrackets($token) { |
113 | 118 | if ($this->baseData instanceof \Transphporm\Functionset && $this->baseData->hasFunction($this->last)) { |
114 | 119 | $this->callTransphpormFunctions($token); |
115 | - } |
|
116 | - else { |
|
120 | + } else { |
|
117 | 121 | $this->processNested($token); |
118 | 122 | } |
119 | 123 | } |
@@ -130,7 +134,9 @@ discard block |
||
130 | 134 | foreach ($this->result->getResult() as $i => $value) { |
131 | 135 | if (is_scalar($value)) { |
132 | 136 | $val = $this->data->read($value); |
133 | - if ($val) $this->result[$i] = $val; |
|
137 | + if ($val) { |
|
138 | + $this->result[$i] = $val; |
|
139 | + } |
|
134 | 140 | } |
135 | 141 | } |
136 | 142 | $this->last = null; |
@@ -142,12 +148,10 @@ discard block |
||
142 | 148 | try { |
143 | 149 | $value = $this->data->extract($this->last, $this->autoLookup); |
144 | 150 | $this->result->processValue($value); |
145 | - } |
|
146 | - catch (\UnexpectedValueException $e) { |
|
151 | + } catch (\UnexpectedValueException $e) { |
|
147 | 152 | if (!$this->autoLookup) { |
148 | 153 | $this->result->processValue($this->last); |
149 | - } |
|
150 | - else { |
|
154 | + } else { |
|
151 | 155 | $this->result->clear(); |
152 | 156 | $this->result[0] = false; |
153 | 157 | } |
@@ -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, $this->valueParser); |
75 | - foreach ($this->pseudo as $pseudoFunction) $pseudoMatcher->registerFunction(clone $pseudoFunction); |
|
77 | + foreach ($this->pseudo as $pseudoFunction) { |
|
78 | + $pseudoMatcher->registerFunction(clone $pseudoFunction); |
|
79 | + } |
|
76 | 80 | return $pseudoMatcher; |
77 | 81 | } |
78 | 82 |
@@ -6,39 +6,39 @@ |
||
6 | 6 | * @version 1.0 */ |
7 | 7 | namespace Transphporm\Parser; |
8 | 8 | class TokenFilterIterator implements \Iterator { |
9 | - private $ignore; |
|
10 | - private $tokens; |
|
9 | + private $ignore; |
|
10 | + private $tokens; |
|
11 | 11 | |
12 | - public function __construct(Tokens $tokens, array $ignore) { |
|
13 | - $this->ignore = $ignore; |
|
14 | - $this->tokens = $tokens; |
|
15 | - } |
|
12 | + public function __construct(Tokens $tokens, array $ignore) { |
|
13 | + $this->ignore = $ignore; |
|
14 | + $this->tokens = $tokens; |
|
15 | + } |
|
16 | 16 | |
17 | - public function current() { |
|
18 | - return $this->tokens->current(); |
|
19 | - } |
|
17 | + public function current() { |
|
18 | + return $this->tokens->current(); |
|
19 | + } |
|
20 | 20 | |
21 | - public function key() { |
|
22 | - return $this->tokens->key(); |
|
23 | - } |
|
21 | + public function key() { |
|
22 | + return $this->tokens->key(); |
|
23 | + } |
|
24 | 24 | |
25 | - public function valid() { |
|
26 | - return $this->tokens->valid(); |
|
27 | - } |
|
25 | + public function valid() { |
|
26 | + return $this->tokens->valid(); |
|
27 | + } |
|
28 | 28 | |
29 | - public function next() { |
|
30 | - do { |
|
31 | - $this->tokens->next(); |
|
32 | - } |
|
33 | - while ($this->shouldContinue()); |
|
34 | - } |
|
29 | + public function next() { |
|
30 | + do { |
|
31 | + $this->tokens->next(); |
|
32 | + } |
|
33 | + while ($this->shouldContinue()); |
|
34 | + } |
|
35 | 35 | |
36 | - public function rewind() { |
|
37 | - $this->tokens->rewind(); |
|
38 | - while ($this->shouldContinue()) $this->tokens->next(); |
|
39 | - } |
|
36 | + public function rewind() { |
|
37 | + $this->tokens->rewind(); |
|
38 | + while ($this->shouldContinue()) $this->tokens->next(); |
|
39 | + } |
|
40 | 40 | |
41 | - private function shouldContinue() { |
|
42 | - return $this->tokens->valid() && in_array($this->tokens->current()['type'], $this->ignore); |
|
43 | - } |
|
41 | + private function shouldContinue() { |
|
42 | + return $this->tokens->valid() && in_array($this->tokens->current()['type'], $this->ignore); |
|
43 | + } |
|
44 | 44 | } |
@@ -35,7 +35,9 @@ |
||
35 | 35 | |
36 | 36 | public function rewind() { |
37 | 37 | $this->tokens->rewind(); |
38 | - while ($this->shouldContinue()) $this->tokens->next(); |
|
38 | + while ($this->shouldContinue()) { |
|
39 | + $this->tokens->next(); |
|
40 | + } |
|
39 | 41 | } |
40 | 42 | |
41 | 43 | private function shouldContinue() { |
@@ -7,6 +7,9 @@ |
||
7 | 7 | $this->templateFunction = $templateFunction; |
8 | 8 | } |
9 | 9 | |
10 | + /** |
|
11 | + * @param string $val |
|
12 | + */ |
|
10 | 13 | public function html($val) { |
11 | 14 | return $this->templateFunction->run([$val]); |
12 | 15 | } |
@@ -1,13 +1,13 @@ |
||
1 | 1 | <?php |
2 | 2 | namespace Transphporm\Formatter; |
3 | 3 | class HTMLFormatter { |
4 | - private $templateFunction; |
|
4 | + private $templateFunction; |
|
5 | 5 | |
6 | - public function __construct(\Transphporm\TSSFunction\Template $templateFunction) { |
|
7 | - $this->templateFunction = $templateFunction; |
|
8 | - } |
|
6 | + public function __construct(\Transphporm\TSSFunction\Template $templateFunction) { |
|
7 | + $this->templateFunction = $templateFunction; |
|
8 | + } |
|
9 | 9 | |
10 | - public function html($val) { |
|
10 | + public function html($val) { |
|
11 | 11 | return $this->templateFunction->run([$val]); |
12 | 12 | } |
13 | 13 |
@@ -14,6 +14,6 @@ |
||
14 | 14 | public function debug($val) { |
15 | 15 | ob_start(); |
16 | 16 | var_dump($val); |
17 | - return $this->html('<pre>' . ob_get_clean() . '</pre>'); |
|
17 | + return $this->html('<pre>'.ob_get_clean().'</pre>'); |
|
18 | 18 | } |
19 | 19 | } |
@@ -26,9 +26,9 @@ |
||
26 | 26 | $tss = $this->readArray($args, 2); |
27 | 27 | |
28 | 28 | if (trim($args[0])[0] === '<') $xml = $args[0]; |
29 | - else $xml = $this->baseDir . $args[0]; |
|
29 | + else $xml = $this->baseDir.$args[0]; |
|
30 | 30 | |
31 | - $newTemplate = new \Transphporm\Builder($xml, $tss ? $this->baseDir . $tss : null); |
|
31 | + $newTemplate = new \Transphporm\Builder($xml, $tss ? $this->baseDir.$tss : null); |
|
32 | 32 | |
33 | 33 | $doc = $newTemplate->output($this->elementData->getData($element), true)->body; |
34 | 34 | if ($selector != '') return $this->templateSubsection($doc, $selector); |
@@ -25,13 +25,18 @@ discard block |
||
25 | 25 | $selector = $this->readArray($args, 1); |
26 | 26 | $tss = $this->readArray($args, 2); |
27 | 27 | |
28 | - if (trim($args[0])[0] === '<') $xml = $args[0]; |
|
29 | - else $xml = $this->baseDir . $args[0]; |
|
28 | + if (trim($args[0])[0] === '<') { |
|
29 | + $xml = $args[0]; |
|
30 | + } else { |
|
31 | + $xml = $this->baseDir . $args[0]; |
|
32 | + } |
|
30 | 33 | |
31 | 34 | $newTemplate = new \Transphporm\Builder($xml, $tss ? $this->baseDir . $tss : null); |
32 | 35 | |
33 | 36 | $doc = $newTemplate->output($this->elementData->getData($element), true)->body; |
34 | - if ($selector != '') return $this->templateSubsection($doc, $selector); |
|
37 | + if ($selector != '') { |
|
38 | + return $this->templateSubsection($doc, $selector); |
|
39 | + } |
|
35 | 40 | |
36 | 41 | return $this->getTemplateContent($doc, $tss); |
37 | 42 | |
@@ -62,7 +67,9 @@ discard block |
||
62 | 67 | |
63 | 68 | private function getClonedElement($node, $tss) { |
64 | 69 | $clone = $node->cloneNode(true); |
65 | - if ($tss != null && $clone instanceof \DomElement) $clone->setAttribute('transphporm', 'includedtemplate'); |
|
70 | + if ($tss != null && $clone instanceof \DomElement) { |
|
71 | + $clone->setAttribute('transphporm', 'includedtemplate'); |
|
72 | + } |
|
66 | 73 | return $clone; |
67 | 74 | } |
68 | 75 | } |
@@ -21,15 +21,13 @@ |
||
21 | 21 | $tokens = $args[0]; |
22 | 22 | $parser = new \Transphporm\Parser\Value($this); |
23 | 23 | $args[0] = $parser->parseTokens($tokens, $this->elementData->getData($this->element)); |
24 | - } |
|
25 | - else if ($args[0] instanceof Parser\Tokens) { |
|
24 | + } else if ($args[0] instanceof Parser\Tokens) { |
|
26 | 25 | $args[0] = iterator_to_array($args[0]); |
27 | 26 | } |
28 | 27 | if (isset($this->functions[$name])) { |
29 | 28 | return $this->functions[$name]->run($args[0], $this->element); |
30 | 29 | } |
31 | - } |
|
32 | - catch (\Exception $e) { |
|
30 | + } catch (\Exception $e) { |
|
33 | 31 | throw new RunException(Exception::TSS_FUNCTION, $name, $e); |
34 | 32 | } |
35 | 33 | return true; |
@@ -1,9 +1,9 @@ |
||
1 | 1 | <?php |
2 | 2 | namespace Transphporm; |
3 | 3 | class RunException extends \Exception { |
4 | - public function __construct($operationType, $operationName, \Exception $previous) { |
|
5 | - $message = 'TSS Error: Problem carrying out ' . $operationType . ' \'' . $operationName . '\''; |
|
4 | + public function __construct($operationType, $operationName, \Exception $previous) { |
|
5 | + $message = 'TSS Error: Problem carrying out ' . $operationType . ' \'' . $operationName . '\''; |
|
6 | 6 | |
7 | - parent::__construct($message, 0, $previous); |
|
8 | - } |
|
7 | + parent::__construct($message, 0, $previous); |
|
8 | + } |
|
9 | 9 | } |
@@ -2,7 +2,7 @@ |
||
2 | 2 | namespace Transphporm; |
3 | 3 | class RunException extends \Exception { |
4 | 4 | public function __construct($operationType, $operationName, \Exception $previous) { |
5 | - $message = 'TSS Error: Problem carrying out ' . $operationType . ' \'' . $operationName . '\''; |
|
5 | + $message = 'TSS Error: Problem carrying out '.$operationType.' \''.$operationName.'\''; |
|
6 | 6 | |
7 | 7 | parent::__construct($message, 0, $previous); |
8 | 8 | } |
@@ -1,14 +1,14 @@ |
||
1 | 1 | <?php |
2 | 2 | namespace Transphporm; |
3 | 3 | class Exception extends \Exception { |
4 | - const PROPERTY = 'property'; |
|
5 | - const TSS_FUNCTION = 'function'; |
|
6 | - const PSEUDO = 'pseudo'; |
|
7 | - const FORMATTER = 'formatter'; |
|
4 | + const PROPERTY = 'property'; |
|
5 | + const TSS_FUNCTION = 'function'; |
|
6 | + const PSEUDO = 'pseudo'; |
|
7 | + const FORMATTER = 'formatter'; |
|
8 | 8 | |
9 | - public function __construct(RunException $runException, $file, $line) { |
|
10 | - $message = $runException->getMessage() . ' on Line ' . $line . ' of ' . ($file === null ? 'tss' : $file); |
|
9 | + public function __construct(RunException $runException, $file, $line) { |
|
10 | + $message = $runException->getMessage() . ' on Line ' . $line . ' of ' . ($file === null ? 'tss' : $file); |
|
11 | 11 | |
12 | - parent::__construct($message, 0, $runException->getPrevious()); |
|
13 | - } |
|
12 | + parent::__construct($message, 0, $runException->getPrevious()); |
|
13 | + } |
|
14 | 14 | } |
@@ -7,7 +7,7 @@ |
||
7 | 7 | const FORMATTER = 'formatter'; |
8 | 8 | |
9 | 9 | public function __construct(RunException $runException, $file, $line) { |
10 | - $message = $runException->getMessage() . ' on Line ' . $line . ' of ' . ($file === null ? 'tss' : $file); |
|
10 | + $message = $runException->getMessage().' on Line '.$line.' of '.($file === null ? 'tss' : $file); |
|
11 | 11 | |
12 | 12 | parent::__construct($message, 0, $runException->getPrevious()); |
13 | 13 | } |