@@ -10,6 +10,9 @@ discard block |
||
10 | 10 | private $elementData; |
11 | 11 | private $line; |
12 | 12 | |
13 | + /** |
|
14 | + * @param integer $line |
|
15 | + */ |
|
13 | 16 | public function __construct(\Transphporm\FunctionSet $functionSet, \Transphporm\Hook\ElementData $elementData, &$line) { |
14 | 17 | $this->functionSet = $functionSet; |
15 | 18 | $this->elementData = $elementData; |
@@ -58,6 +61,12 @@ discard block |
||
58 | 61 | return $value; |
59 | 62 | } |
60 | 63 | |
64 | + /** |
|
65 | + * @param \DOMElement $element |
|
66 | + * @param integer $count |
|
67 | + * |
|
68 | + * @return \DOMElement |
|
69 | + */ |
|
61 | 70 | private function cloneElement($element, $iteration, $key, $count) { |
62 | 71 | $clone = $element->cloneNode(true); |
63 | 72 | $this->tagElement($clone, $count); |
@@ -77,6 +86,9 @@ discard block |
||
77 | 86 | return isset($values[1]) ? $values[1] : PHP_INT_MAX; |
78 | 87 | } |
79 | 88 | |
89 | + /** |
|
90 | + * @param \Transphporm\Hook\PseudoMatcher $pseudoMatcher |
|
91 | + */ |
|
80 | 92 | private function createHook($newRules, $pseudoMatcher, $properties) { |
81 | 93 | $var = ""; // PropertyHook requires that baseDir be passed by refrence |
82 | 94 | // and there is no reason to pass it so create $var to avoid errors |
@@ -18,7 +18,9 @@ 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 | |
@@ -29,7 +31,9 @@ discard block |
||
29 | 31 | $hook = $this->createHook($rules, $pseudoMatcher, $properties); |
30 | 32 | |
31 | 33 | foreach ($repeat as $key => $iteration) { |
32 | - if ($count+1 > $max) break; |
|
34 | + if ($count+1 > $max) { |
|
35 | + break; |
|
36 | + } |
|
33 | 37 | $clone = $this->cloneElement($element, $iteration, $key, $count++); |
34 | 38 | //Re-run the hook on the new element, but use the iterated data |
35 | 39 | $hook->run($clone); |
@@ -41,8 +45,9 @@ discard block |
||
41 | 45 | |
42 | 46 | private function getRepeatValue($values, &$max) { |
43 | 47 | $mode = $this->getMode($values); |
44 | - if ($mode === 'each') $repeat = $values[0]; |
|
45 | - else if ($mode === 'loop') { |
|
48 | + if ($mode === 'each') { |
|
49 | + $repeat = $values[0]; |
|
50 | + } else if ($mode === 'loop') { |
|
46 | 51 | $repeat = range($values[0], $max); |
47 | 52 | $max++; |
48 | 53 | } |
@@ -54,7 +59,9 @@ discard block |
||
54 | 59 | } |
55 | 60 | |
56 | 61 | private function fixEmpty($value) { |
57 | - if (empty($value[0])) $value[0] = []; |
|
62 | + if (empty($value[0])) { |
|
63 | + $value[0] = []; |
|
64 | + } |
|
58 | 65 | return $value; |
59 | 66 | } |
60 | 67 | |
@@ -70,7 +77,9 @@ discard block |
||
70 | 77 | |
71 | 78 | private function tagElement($element, $count) { |
72 | 79 | //Mark all but one of the nodes as having been added by transphporm, when the hook is run again, these are removed |
73 | - if ($count > 0) $element->setAttribute('transphporm', 'added'); |
|
80 | + if ($count > 0) { |
|
81 | + $element->setAttribute('transphporm', 'added'); |
|
82 | + } |
|
74 | 83 | } |
75 | 84 | |
76 | 85 | private function getMax($values) { |
@@ -81,7 +90,9 @@ discard block |
||
81 | 90 | $var = ""; // PropertyHook requires that baseDir be passed by refrence |
82 | 91 | // and there is no reason to pass it so create $var to avoid errors |
83 | 92 | $hook = new \Transphporm\Hook\PropertyHook($newRules, $var, $this->line, "", $this->line, $pseudoMatcher, new \Transphporm\Parser\Value($this->functionSet), $this->functionSet); |
84 | - foreach ($properties as $name => $property) $hook->registerProperty($name, $property); |
|
93 | + foreach ($properties as $name => $property) { |
|
94 | + $hook->registerProperty($name, $property); |
|
95 | + } |
|
85 | 96 | return $hook; |
86 | 97 | } |
87 | 98 | } |
@@ -2,16 +2,16 @@ |
||
2 | 2 | namespace Transphporm; |
3 | 3 | |
4 | 4 | class FilePath { |
5 | - private $baseDir; |
|
6 | - private $customBase; |
|
5 | + private $baseDir; |
|
6 | + private $customBase; |
|
7 | 7 | |
8 | - public function __construct(&$baseDir, $customBase = null) { |
|
9 | - $this->baseDir = &$baseDir; |
|
10 | - if ($customBase === null) $this->customBase = getcwd(); |
|
11 | - else $this->customBase = rtrim($customBase, '/'); |
|
12 | - } |
|
8 | + public function __construct(&$baseDir, $customBase = null) { |
|
9 | + $this->baseDir = &$baseDir; |
|
10 | + if ($customBase === null) $this->customBase = getcwd(); |
|
11 | + else $this->customBase = rtrim($customBase, '/'); |
|
12 | + } |
|
13 | 13 | |
14 | - public function getFilePath($filePath = "") { |
|
14 | + public function getFilePath($filePath = "") { |
|
15 | 15 | if (isset($filePath[0]) && $filePath[0] == "/") return $this->customBase . $filePath; |
16 | 16 | else return $this->baseDir . $filePath; |
17 | 17 | } |
@@ -3,40 +3,40 @@ |
||
3 | 3 | namespace Transphporm\TSSFunction; |
4 | 4 | |
5 | 5 | class Math implements \Transphporm\TSSFunction { |
6 | - private $mode; |
|
7 | - |
|
8 | - const ADD = 'add'; |
|
9 | - const SUBTRACT = 'sub'; |
|
10 | - const MULTIPLY = 'mult'; |
|
11 | - const DIVIDE = 'div'; |
|
12 | - |
|
13 | - public function __construct($mode) { |
|
14 | - $this->mode = $mode; |
|
15 | - } |
|
16 | - |
|
17 | - public function run(array $args, \DomElement $element) { |
|
18 | - $result = $args[0]; |
|
19 | - for ($i = 1; $i < count($args); $i++) $result = $this->getModeResult($args[$i], $result); |
|
20 | - return $result; |
|
21 | - } |
|
22 | - |
|
23 | - private function getModeResult($val, $prev) { |
|
24 | - return $this->{$this->mode}($val, $prev); |
|
25 | - } |
|
26 | - |
|
27 | - private function add($val, $prev) { |
|
28 | - return $prev+$val; |
|
29 | - } |
|
30 | - |
|
31 | - private function sub($val, $prev) { |
|
32 | - return $prev-$val; |
|
33 | - } |
|
34 | - |
|
35 | - private function mult($val, $prev) { |
|
36 | - return $prev*$val; |
|
37 | - } |
|
38 | - |
|
39 | - private function div($val, $prev) { |
|
40 | - return $prev/$val; |
|
41 | - } |
|
6 | + private $mode; |
|
7 | + |
|
8 | + const ADD = 'add'; |
|
9 | + const SUBTRACT = 'sub'; |
|
10 | + const MULTIPLY = 'mult'; |
|
11 | + const DIVIDE = 'div'; |
|
12 | + |
|
13 | + public function __construct($mode) { |
|
14 | + $this->mode = $mode; |
|
15 | + } |
|
16 | + |
|
17 | + public function run(array $args, \DomElement $element) { |
|
18 | + $result = $args[0]; |
|
19 | + for ($i = 1; $i < count($args); $i++) $result = $this->getModeResult($args[$i], $result); |
|
20 | + return $result; |
|
21 | + } |
|
22 | + |
|
23 | + private function getModeResult($val, $prev) { |
|
24 | + return $this->{$this->mode}($val, $prev); |
|
25 | + } |
|
26 | + |
|
27 | + private function add($val, $prev) { |
|
28 | + return $prev+$val; |
|
29 | + } |
|
30 | + |
|
31 | + private function sub($val, $prev) { |
|
32 | + return $prev-$val; |
|
33 | + } |
|
34 | + |
|
35 | + private function mult($val, $prev) { |
|
36 | + return $prev*$val; |
|
37 | + } |
|
38 | + |
|
39 | + private function div($val, $prev) { |
|
40 | + return $prev/$val; |
|
41 | + } |
|
42 | 42 | } |
@@ -33,10 +33,10 @@ |
||
33 | 33 | } |
34 | 34 | |
35 | 35 | private function mult($val, $prev) { |
36 | - return $prev*$val; |
|
36 | + return $prev * $val; |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | private function div($val, $prev) { |
40 | - return $prev/$val; |
|
40 | + return $prev / $val; |
|
41 | 41 | } |
42 | 42 | } |
@@ -1,29 +1,29 @@ |
||
1 | 1 | <?php |
2 | 2 | namespace Transphporm\TSSFunction; |
3 | 3 | class Json implements \Transphporm\TSSFunction { |
4 | - private $filePath; |
|
4 | + private $filePath; |
|
5 | 5 | |
6 | - public function __construct(\Transphporm\FilePath $filePath) { |
|
7 | - $this->filePath = $filePath; |
|
8 | - } |
|
6 | + public function __construct(\Transphporm\FilePath $filePath) { |
|
7 | + $this->filePath = $filePath; |
|
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 ($this->isJsonFile($json)) { |
|
14 | - $path = $this->filePath->getFilePath($json); |
|
15 | - if (!file_exists($path)) throw new \Exception('File does not exist at: ' . $path); |
|
16 | - $json = file_get_contents($path); |
|
17 | - } |
|
13 | + if ($this->isJsonFile($json)) { |
|
14 | + $path = $this->filePath->getFilePath($json); |
|
15 | + if (!file_exists($path)) throw new \Exception('File does not exist at: ' . $path); |
|
16 | + $json = file_get_contents($path); |
|
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 | |
26 | - private function isJsonFile($json) { |
|
27 | - return trim($json)[0] != '{' && trim($json)[0] != '['; |
|
28 | - } |
|
26 | + private function isJsonFile($json) { |
|
27 | + return trim($json)[0] != '{' && trim($json)[0] != '['; |
|
28 | + } |
|
29 | 29 | } |