@@ -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 | } |
@@ -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 | } |
@@ -28,8 +28,7 @@ discard block |
||
28 | 28 | try { |
29 | 29 | $parts = $this->getFuncParts($tokens); |
30 | 30 | $matches = $matches && $function->match($parts['name'], $parts['args'], $element); |
31 | - } |
|
32 | - catch (\Exception $e) { |
|
31 | + } catch (\Exception $e) { |
|
33 | 32 | throw new \Transphporm\RunException(\Transphporm\Exception::PSEUDO, $parts['name'], $e); |
34 | 33 | } |
35 | 34 | } |
@@ -42,31 +41,37 @@ discard block |
||
42 | 41 | $parts['name'] = $this->getFuncName($tokens); |
43 | 42 | if ($parts['name'] === null || in_array($parts['name'], ['data', 'iteration', 'root'])) { |
44 | 43 | $parts['args'] = $this->valueParser->parseTokens($tokens); |
45 | - } |
|
46 | - else if (count($tokens) > 1) { |
|
44 | + } else if (count($tokens) > 1) { |
|
47 | 45 | $tokens->rewind(); |
48 | 46 | $tokens->next(); |
49 | 47 | $parts['args'] = $this->valueParser->parseTokens($tokens->current()['value']); |
48 | + } else { |
|
49 | + $parts['args'] = [['']]; |
|
50 | 50 | } |
51 | - else $parts['args'] = [['']]; |
|
52 | 51 | return $parts; |
53 | 52 | } |
54 | 53 | |
55 | 54 | private function getFuncName($tokens) { |
56 | - if ($tokens->type() === Tokenizer::NAME) return $tokens->read(); |
|
55 | + if ($tokens->type() === Tokenizer::NAME) { |
|
56 | + return $tokens->read(); |
|
57 | + } |
|
57 | 58 | return null; |
58 | 59 | } |
59 | 60 | |
60 | 61 | public function hasFunction($name) { |
61 | 62 | foreach ($this->pseudo as $tokens) { |
62 | - if ($name === $this->getFuncName($tokens)) return true; |
|
63 | + if ($name === $this->getFuncName($tokens)) { |
|
64 | + return true; |
|
65 | + } |
|
63 | 66 | } |
64 | 67 | } |
65 | 68 | |
66 | 69 | public function getFuncArgs($name) { |
67 | 70 | foreach ($this->pseudo as $tokens) { |
68 | 71 | $parts = $this->getFuncParts($tokens); |
69 | - if ($name === $parts['name']) return $parts['args']; |
|
72 | + if ($name === $parts['name']) { |
|
73 | + return $parts['args']; |
|
74 | + } |
|
70 | 75 | } |
71 | 76 | } |
72 | 77 | } |