@@ -19,7 +19,9 @@ |
||
19 | 19 | $close = strpos($this->str, $closingChr, $open); |
20 | 20 | |
21 | 21 | $cPos = $open+1; |
22 | - while (($cPos = strpos($this->str, $openChr, $cPos+1)) !== false && $cPos < $close) $close = strpos($this->str, $closingChr, $close+1); |
|
22 | + while (($cPos = strpos($this->str, $openChr, $cPos+1)) !== false && $cPos < $close) { |
|
23 | + $close = strpos($this->str, $closingChr, $close+1); |
|
24 | + } |
|
23 | 25 | |
24 | 26 | $this->startPos = $open; |
25 | 27 | $this->endPos = $close; |
@@ -20,11 +20,15 @@ discard block |
||
20 | 20 | |
21 | 21 | public function run(\DomElement $element) { |
22 | 22 | //Don't run if there's a pseudo element like nth-child() and this element doesn't match it |
23 | - if (!$this->pseudoMatcher->matches($element)) return; |
|
23 | + if (!$this->pseudoMatcher->matches($element)) { |
|
24 | + return; |
|
25 | + } |
|
24 | 26 | |
25 | 27 | foreach ($this->rules as $name => $value) { |
26 | 28 | $result = $this->callProperty($name, $element, $this->valueParser->parse(trim($value), $element)); |
27 | - if ($result === false) break; |
|
29 | + if ($result === false) { |
|
30 | + break; |
|
31 | + } |
|
28 | 32 | } |
29 | 33 | } |
30 | 34 | |
@@ -45,7 +49,9 @@ discard block |
||
45 | 49 | } |
46 | 50 | |
47 | 51 | private function callProperty($name, $element, $value) { |
48 | - if (isset($this->properties[$name])) return $this->properties[$name]->run($value, $element, $this->rules, $this->pseudoMatcher, $this->properties); |
|
52 | + if (isset($this->properties[$name])) { |
|
53 | + return $this->properties[$name]->run($value, $element, $this->rules, $this->pseudoMatcher, $this->properties); |
|
54 | + } |
|
49 | 55 | return false; |
50 | 56 | } |
51 | 57 | } |
@@ -7,8 +7,12 @@ |
||
7 | 7 | namespace Transphporm\Property; |
8 | 8 | class Display implements \Transphporm\Property { |
9 | 9 | public function run($value, \DomElement $element, array $rules, \Transphporm\Hook\PseudoMatcher $pseudoMatcher, array $properties = []) { |
10 | - if ($pseudoMatcher->hasFunction('attr')) $element->removeAttribute($pseudoMatcher->getFuncArgs('attr')); |
|
11 | - else if (strtolower($value[0]) === 'none') $element->setAttribute('transphporm', 'remove'); |
|
12 | - else $element->setAttribute('transphporm', 'show'); |
|
10 | + if ($pseudoMatcher->hasFunction('attr')) { |
|
11 | + $element->removeAttribute($pseudoMatcher->getFuncArgs('attr')); |
|
12 | + } else if (strtolower($value[0]) === 'none') { |
|
13 | + $element->setAttribute('transphporm', 'remove'); |
|
14 | + } else { |
|
15 | + $element->setAttribute('transphporm', 'show'); |
|
16 | + } |
|
13 | 17 | } |
14 | 18 | } |
15 | 19 | \ No newline at end of file |
@@ -14,10 +14,14 @@ discard block |
||
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->dataFunction, $name])) return true; |
|
22 | + if (!is_callable([$this->dataFunction, $name])) { |
|
23 | + return true; |
|
24 | + } |
|
21 | 25 | |
22 | 26 | $bracketMatcher = new \Transphporm\Parser\BracketMatcher($pseudo); |
23 | 27 | $criteria = $bracketMatcher->match('[', ']'); |
@@ -42,16 +46,21 @@ discard block |
||
42 | 46 | } |
43 | 47 | |
44 | 48 | private function parseValue($value) { |
45 | - if ($value == 'true') return true; |
|
46 | - else if ($value == 'false') return false; |
|
47 | - else return $value; |
|
49 | + if ($value == 'true') { |
|
50 | + return true; |
|
51 | + } else if ($value == 'false') { |
|
52 | + return false; |
|
53 | + } else { |
|
54 | + return $value; |
|
55 | + } |
|
48 | 56 | } |
49 | 57 | |
50 | 58 | private function getOperator($field) { |
51 | 59 | if ($field[strlen($field)-1] == '!') { |
52 | 60 | return '!'; |
61 | + } else { |
|
62 | + return ''; |
|
53 | 63 | } |
54 | - else return ''; |
|
55 | 64 | } |
56 | 65 | |
57 | 66 | } |
58 | 67 | \ No newline at end of file |
@@ -15,8 +15,11 @@ |
||
15 | 15 | $bracketMatcher = new \Transphporm\Parser\BracketMatcher($element->getNodePath()); |
16 | 16 | $num = $bracketMatcher->match('[', ']'); |
17 | 17 | |
18 | - if (is_callable([$this, $criteria])) return $this->$criteria($num); |
|
19 | - else return $num == $criteria; |
|
18 | + if (is_callable([$this, $criteria])) { |
|
19 | + return $this->$criteria($num); |
|
20 | + } else { |
|
21 | + return $num == $criteria; |
|
22 | + } |
|
20 | 23 | } |
21 | 24 | return true; |
22 | 25 | } |
@@ -31,7 +31,9 @@ discard block |
||
31 | 31 | |
32 | 32 | public function hasFunction($name) { |
33 | 33 | foreach ($this->pseudo as $pseudo) { |
34 | - if (strpos($pseudo, $name) === 0) return true; |
|
34 | + if (strpos($pseudo, $name) === 0) { |
|
35 | + return true; |
|
36 | + } |
|
35 | 37 | } |
36 | 38 | } |
37 | 39 | |
@@ -50,10 +52,16 @@ discard block |
||
50 | 52 | $parenthesis = strpos($pseudo, '('); |
51 | 53 | $square = strpos($pseudo, ']'); |
52 | 54 | |
53 | - if ($parenthesis === false) $parenthesis = 999; |
|
54 | - if ($square === false) $square = 999; |
|
55 | + if ($parenthesis === false) { |
|
56 | + $parenthesis = 999; |
|
57 | + } |
|
58 | + if ($square === false) { |
|
59 | + $square = 999; |
|
60 | + } |
|
55 | 61 | |
56 | - if ($parenthesis < $square) return ['(', ')']; |
|
62 | + if ($parenthesis < $square) { |
|
63 | + return ['(', ')']; |
|
64 | + } |
|
57 | 65 | return ['[', ']']; |
58 | 66 | } |
59 | 67 |
@@ -30,7 +30,9 @@ |
||
30 | 30 | //Find all nodes matched by the expressions in the brackets :not(EXPR) |
31 | 31 | foreach ($xpath->query($xpathString) as $matchedElement) { |
32 | 32 | //Check to see whether this node was matched by the not query |
33 | - if ($element->isSameNode($matchedElement)) return false; |
|
33 | + if ($element->isSameNode($matchedElement)) { |
|
34 | + return false; |
|
35 | + } |
|
34 | 36 | } |
35 | 37 | } |
36 | 38 | return true; |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | |
50 | 50 | $cachedOutput = $this->loadTemplate(); |
51 | 51 | //To be a valid XML document it must have a root element, automatically wrap it in <template> to ensure it does |
52 | - $template = new Template($this->isValidDoc($cachedOutput['body']) ? str_ireplace('<!doctype', '<!DOCTYPE', $cachedOutput['body']) : '<template>' . $cachedOutput['body'] . '</template>' ); |
|
52 | + $template = new Template($this->isValidDoc($cachedOutput['body']) ? str_ireplace('<!doctype', '<!DOCTYPE', $cachedOutput['body']) : '<template>'.$cachedOutput['body'].'</template>'); |
|
53 | 53 | |
54 | 54 | $this->processRules($template, $data, $featureSet); |
55 | 55 | |
@@ -98,11 +98,11 @@ discard block |
||
98 | 98 | //N.b. only files can be cached |
99 | 99 | private function getRules($template, $valueParser) { |
100 | 100 | if (is_file($this->tss)) { |
101 | - $this->baseDir = dirname(realpath($this->tss)) . DIRECTORY_SEPARATOR; |
|
101 | + $this->baseDir = dirname(realpath($this->tss)).DIRECTORY_SEPARATOR; |
|
102 | 102 | //The cache for the key: the filename and template prefix |
103 | 103 | //Each template may have a different prefix which changes the parsed TSS, |
104 | 104 | //Because of this the cache needs to be generated for each template prefix. |
105 | - $key = $this->tss . $template->getPrefix() . $this->baseDir; |
|
105 | + $key = $this->tss.$template->getPrefix().$this->baseDir; |
|
106 | 106 | //Try to load the cached rules, if not set in the cache (or expired) parse the supplied sheet |
107 | 107 | $rules = $this->cache->load($key, filemtime($this->tss)); |
108 | 108 | if (!$rules) return $this->cache->write($key, (new Parser\Sheet(file_get_contents($this->tss), $this->baseDir, $valueParser, $template->getPrefix()))->parse()); |
@@ -25,7 +25,9 @@ discard block |
||
25 | 25 | $this->cache = new Cache(new \ArrayObject()); |
26 | 26 | |
27 | 27 | $modules = is_array($modules) ? $modules : $this->defaultModules; |
28 | - foreach ($modules as $module) $this->loadModule(new $module); |
|
28 | + foreach ($modules as $module) { |
|
29 | + $this->loadModule(new $module); |
|
30 | + } |
|
29 | 31 | } |
30 | 32 | |
31 | 33 | //Allow setting the time used by Transphporm for caching. This is for testing purposes |
@@ -44,7 +46,9 @@ discard block |
||
44 | 46 | $data = new Hook\DataFunction(new \SplObjectStorage(), $data, $this->baseDir); |
45 | 47 | $featureSet = new FeatureSet($data, new Hook\Formatter(), $headers); |
46 | 48 | |
47 | - foreach ($this->modules as $module) $module->load($featureSet); |
|
49 | + foreach ($this->modules as $module) { |
|
50 | + $module->load($featureSet); |
|
51 | + } |
|
48 | 52 | //$locale = $this->getLocale(); |
49 | 53 | |
50 | 54 | $cachedOutput = $this->loadTemplate(); |
@@ -63,7 +67,9 @@ discard block |
||
63 | 67 | private function processRules($template, $data, $featureSet) { |
64 | 68 | $valueParser = new Parser\Value($data); |
65 | 69 | foreach ($this->getRules($template, $valueParser) as $rule) { |
66 | - if ($rule->shouldRun($this->time)) $this->executeTssRule($rule, $template, $valueParser, $featureSet); |
|
70 | + if ($rule->shouldRun($this->time)) { |
|
71 | + $this->executeTssRule($rule, $template, $valueParser, $featureSet); |
|
72 | + } |
|
67 | 73 | } |
68 | 74 | } |
69 | 75 | |
@@ -90,8 +96,9 @@ discard block |
||
90 | 96 | if (trim($this->template)[0] !== '<') { |
91 | 97 | $xml = $this->cache->load($this->template, filemtime($this->template)); |
92 | 98 | return $xml ? $xml : ['body' => file_get_contents($this->template), 'headers' => []]; |
99 | + } else { |
|
100 | + return ['body' => $this->template, 'headers' => []]; |
|
93 | 101 | } |
94 | - else return ['body' => $this->template, 'headers' => []]; |
|
95 | 102 | } |
96 | 103 | |
97 | 104 | //Load the TSS rules either from a file or as a string |
@@ -105,10 +112,14 @@ discard block |
||
105 | 112 | $key = $this->tss . $template->getPrefix() . $this->baseDir; |
106 | 113 | //Try to load the cached rules, if not set in the cache (or expired) parse the supplied sheet |
107 | 114 | $rules = $this->cache->load($key, filemtime($this->tss)); |
108 | - if (!$rules) return $this->cache->write($key, (new Parser\Sheet(file_get_contents($this->tss), $this->baseDir, $valueParser, $template->getPrefix()))->parse()); |
|
109 | - else return $rules; |
|
115 | + if (!$rules) { |
|
116 | + return $this->cache->write($key, (new Parser\Sheet(file_get_contents($this->tss), $this->baseDir, $valueParser, $template->getPrefix()))->parse()); |
|
117 | + } else { |
|
118 | + return $rules; |
|
119 | + } |
|
120 | + } else { |
|
121 | + return (new Parser\Sheet($this->tss, $this->baseDir, $valueParser, $template->getPrefix()))->parse(); |
|
110 | 122 | } |
111 | - else return (new Parser\Sheet($this->tss, $this->baseDir, $valueParser, $template->getPrefix()))->parse(); |
|
112 | 123 | } |
113 | 124 | |
114 | 125 | public function setCache(\ArrayAccess $cache) { |
@@ -35,12 +35,16 @@ |
||
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 |