@@ -40,7 +40,7 @@ |
||
40 | 40 | private function getTemplateContent($newNode, $tss) { |
41 | 41 | $result = []; |
42 | 42 | foreach ($newNode->childNodes as $node) { |
43 | - if (isset($node->tagName) && $node->tagName === 'template') $result[] = $this->getTemplateContent($node, $tss); |
|
43 | + if (isset($node->tagName) && $node->tagName === 'template') $result[] = $this->getTemplateContent($node, $tss); |
|
44 | 44 | else $result[] = $this->getClonedElement($node, $tss); |
45 | 45 | } |
46 | 46 | return $result; |
@@ -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->filePath->getFilePath($args[0]); |
|
28 | + if (trim($args[0])[0] === '<') { |
|
29 | + $xml = $args[0]; |
|
30 | + } else { |
|
31 | + $xml = $this->filePath->getFilePath($args[0]); |
|
32 | + } |
|
30 | 33 | |
31 | 34 | $newTemplate = new \Transphporm\Builder($xml, $tss ? $this->filePath->getFilePath($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->documentElement, $tss); |
37 | 42 | } |
@@ -39,8 +44,11 @@ discard block |
||
39 | 44 | private function getTemplateContent($newNode, $tss) { |
40 | 45 | $result = []; |
41 | 46 | foreach ($newNode->childNodes as $node) { |
42 | - if (isset($node->tagName) && $node->tagName === 'template') $result[] = $this->getTemplateContent($node, $tss); |
|
43 | - else $result[] = $this->getClonedElement($node, $tss); |
|
47 | + if (isset($node->tagName) && $node->tagName === 'template') { |
|
48 | + $result[] = $this->getTemplateContent($node, $tss); |
|
49 | + } else { |
|
50 | + $result[] = $this->getClonedElement($node, $tss); |
|
51 | + } |
|
44 | 52 | } |
45 | 53 | return $result; |
46 | 54 | } |
@@ -59,7 +67,9 @@ discard block |
||
59 | 67 | |
60 | 68 | private function getClonedElement($node, $tss) { |
61 | 69 | $clone = $node->cloneNode(true); |
62 | - if ($tss != null && $clone instanceof \DomElement) $clone->setAttribute('transphporm', 'includedtemplate'); |
|
70 | + if ($tss != null && $clone instanceof \DomElement) { |
|
71 | + $clone->setAttribute('transphporm', 'includedtemplate'); |
|
72 | + } |
|
63 | 73 | return $clone; |
64 | 74 | } |
65 | 75 | } |
@@ -25,7 +25,9 @@ discard block |
||
25 | 25 | foreach ($this->pseudo as $tokens) { |
26 | 26 | foreach ($this->functions as $function) { |
27 | 27 | $matches = $this->match($tokens, $function, $element); |
28 | - if ($matches === false) return false; |
|
28 | + if ($matches === false) { |
|
29 | + return false; |
|
30 | + } |
|
29 | 31 | } |
30 | 32 | } |
31 | 33 | return true; |
@@ -35,9 +37,10 @@ discard block |
||
35 | 37 | try { |
36 | 38 | $parts = $this->getFuncParts($tokens); |
37 | 39 | $matches = $function->match($parts['name'], $parts['args'], $element); |
38 | - if ($matches === false) return false; |
|
39 | - } |
|
40 | - catch (\Exception $e) { |
|
40 | + if ($matches === false) { |
|
41 | + return false; |
|
42 | + } |
|
43 | + } catch (\Exception $e) { |
|
41 | 44 | throw new \Transphporm\RunException(\Transphporm\Exception::PSEUDO, $parts['name'], $e); |
42 | 45 | } |
43 | 46 | } |
@@ -46,31 +49,37 @@ discard block |
||
46 | 49 | $parts['name'] = $this->getFuncName($tokens); |
47 | 50 | if ($parts['name'] === null || in_array($parts['name'], ['data', 'iteration', 'root'])) { |
48 | 51 | $parts['args'] = $this->valueParser->parseTokens($tokens); |
49 | - } |
|
50 | - else if (count($tokens) > 1) { |
|
52 | + } else if (count($tokens) > 1) { |
|
51 | 53 | $tokens->rewind(); |
52 | 54 | $tokens->next(); |
53 | 55 | $parts['args'] = $this->valueParser->parseTokens($tokens->current()['value']); |
56 | + } else { |
|
57 | + $parts['args'] = [['']]; |
|
54 | 58 | } |
55 | - else $parts['args'] = [['']]; |
|
56 | 59 | return $parts; |
57 | 60 | } |
58 | 61 | |
59 | 62 | private function getFuncName($tokens) { |
60 | - if ($tokens->type() === Tokenizer::NAME) return $tokens->read(); |
|
63 | + if ($tokens->type() === Tokenizer::NAME) { |
|
64 | + return $tokens->read(); |
|
65 | + } |
|
61 | 66 | return null; |
62 | 67 | } |
63 | 68 | |
64 | 69 | public function hasFunction($name) { |
65 | 70 | foreach ($this->pseudo as $tokens) { |
66 | - if ($name === $this->getFuncName($tokens)) return true; |
|
71 | + if ($name === $this->getFuncName($tokens)) { |
|
72 | + return true; |
|
73 | + } |
|
67 | 74 | } |
68 | 75 | } |
69 | 76 | |
70 | 77 | public function getFuncArgs($name) { |
71 | 78 | foreach ($this->pseudo as $tokens) { |
72 | 79 | $parts = $this->getFuncParts($tokens); |
73 | - if ($name === $parts['name']) return $parts['args']; |
|
80 | + if ($name === $parts['name']) { |
|
81 | + return $parts['args']; |
|
82 | + } |
|
74 | 83 | } |
75 | 84 | } |
76 | 85 | } |
@@ -9,13 +9,13 @@ |
||
9 | 9 | private $functionSet; |
10 | 10 | private $elementData; |
11 | 11 | private $line; |
12 | - private $filePath; |
|
12 | + private $filePath; |
|
13 | 13 | |
14 | 14 | public function __construct(\Transphporm\FunctionSet $functionSet, \Transphporm\Hook\ElementData $elementData, &$line, \Transphporm\FilePath $filePath) { |
15 | 15 | $this->functionSet = $functionSet; |
16 | 16 | $this->elementData = $elementData; |
17 | 17 | $this->line = &$line; |
18 | - $this->filePath = $filePath; |
|
18 | + $this->filePath = $filePath; |
|
19 | 19 | } |
20 | 20 | |
21 | 21 | public function run(array $values, \DomElement $element, array $rules, \Transphporm\Hook\PseudoMatcher $pseudoMatcher, array $properties = []) { |
@@ -20,7 +20,9 @@ discard block |
||
20 | 20 | |
21 | 21 | public function run(array $values, \DomElement $element, array $rules, \Transphporm\Hook\PseudoMatcher $pseudoMatcher, array $properties = []) { |
22 | 22 | $values = $this->fixEmpty($values); |
23 | - if ($element->getAttribute('transphporm') === 'added') return $element->parentNode->removeChild($element); |
|
23 | + if ($element->getAttribute('transphporm') === 'added') { |
|
24 | + return $element->parentNode->removeChild($element); |
|
25 | + } |
|
24 | 26 | $max = $this->getMax($values); |
25 | 27 | $count = 0; |
26 | 28 | $repeat = $this->getRepeatValue($values, $max); |
@@ -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); |
@@ -55,7 +59,9 @@ discard block |
||
55 | 59 | } |
56 | 60 | |
57 | 61 | private function fixEmpty($value) { |
58 | - if (empty($value[0])) $value[0] = []; |
|
62 | + if (empty($value[0])) { |
|
63 | + $value[0] = []; |
|
64 | + } |
|
59 | 65 | return $value; |
60 | 66 | } |
61 | 67 | |
@@ -71,7 +77,9 @@ discard block |
||
71 | 77 | |
72 | 78 | private function tagElement($element, $count) { |
73 | 79 | //Mark all but one of the nodes as having been added by transphporm, when the hook is run again, these are removed |
74 | - if ($count > 0) $element->setAttribute('transphporm', 'added'); |
|
80 | + if ($count > 0) { |
|
81 | + $element->setAttribute('transphporm', 'added'); |
|
82 | + } |
|
75 | 83 | } |
76 | 84 | |
77 | 85 | private function getMax($values) { |
@@ -80,7 +88,9 @@ discard block |
||
80 | 88 | |
81 | 89 | private function createHook($newRules, $pseudoMatcher, $properties) { |
82 | 90 | $hook = new \Transphporm\Hook\PropertyHook($newRules, $this->line, null, $this->line, $pseudoMatcher, new \Transphporm\Parser\Value($this->functionSet), $this->functionSet, $this->filePath); |
83 | - foreach ($properties as $name => $property) $hook->registerProperty($name, $property); |
|
91 | + foreach ($properties as $name => $property) { |
|
92 | + $hook->registerProperty($name, $property); |
|
93 | + } |
|
84 | 94 | return $hook; |
85 | 95 | } |
86 | 96 | } |
@@ -20,8 +20,7 @@ discard block |
||
20 | 20 | if (isset($this->functions[$name])) { |
21 | 21 | return $this->functions[$name]->run($this->getArgs0($name, $args), $this->element); |
22 | 22 | } |
23 | - } |
|
24 | - catch (\Exception $e) { |
|
23 | + } catch (\Exception $e) { |
|
25 | 24 | throw new RunException(Exception::TSS_FUNCTION, $name, $e); |
26 | 25 | } |
27 | 26 | return false; |
@@ -32,8 +31,7 @@ discard block |
||
32 | 31 | $tokens = $args[0]; |
33 | 32 | $parser = new \Transphporm\Parser\Value($this); |
34 | 33 | return $parser->parseTokens($tokens, $this->elementData->getData($this->element)); |
35 | - } |
|
36 | - else if ($args[0] instanceof Parser\Tokens) { |
|
34 | + } else if ($args[0] instanceof Parser\Tokens) { |
|
37 | 35 | return iterator_to_array($args[0]); |
38 | 36 | } |
39 | 37 |
@@ -7,11 +7,11 @@ discard block |
||
7 | 7 | namespace Transphporm\Pseudo; |
8 | 8 | class Not implements \Transphporm\Pseudo { |
9 | 9 | private $cssToXpath; |
10 | - private $config; |
|
10 | + private $config; |
|
11 | 11 | |
12 | 12 | public function __construct(\Transphporm\Parser\CssToXpath $cssToXpath, \Transphporm\Config $config) { |
13 | 13 | $this->cssToXpath = $cssToXpath; |
14 | - $this->config = $config; |
|
14 | + $this->config = $config; |
|
15 | 15 | } |
16 | 16 | |
17 | 17 | public function match($name, $args, \DomElement $element) { |
@@ -26,19 +26,19 @@ discard block |
||
26 | 26 | foreach ($css as $selector) { |
27 | 27 | $tokenizer = new \Transphporm\Parser\Tokenizer($selector); |
28 | 28 | $xpathString = $this->cssToXpath->getXpath($tokenizer->getTokens()); |
29 | - $pseudo = $this->cssToXpath->getPseudo($tokenizer->getTokens()); |
|
30 | - $pseudoMatcher = $this->config->createPseudoMatcher($pseudo); |
|
29 | + $pseudo = $this->cssToXpath->getPseudo($tokenizer->getTokens()); |
|
30 | + $pseudoMatcher = $this->config->createPseudoMatcher($pseudo); |
|
31 | 31 | if ($this->matches($xpath->query($xpathString), $element, $pseudoMatcher)) return false; |
32 | 32 | } |
33 | 33 | return true; |
34 | 34 | } |
35 | 35 | |
36 | - private function matches($foundElements, $element, $pseudoMatcher) { |
|
37 | - //Find all nodes matched by the expressions in the brackets :not(EXPR) |
|
38 | - foreach ($foundElements as $matchedElement) { |
|
39 | - //Check to see whether this node was matched by the not query |
|
40 | - if ($pseudoMatcher->matches($matchedElement) && $element->isSameNode($matchedElement)) return true; |
|
41 | - } |
|
42 | - return false; |
|
43 | - } |
|
36 | + private function matches($foundElements, $element, $pseudoMatcher) { |
|
37 | + //Find all nodes matched by the expressions in the brackets :not(EXPR) |
|
38 | + foreach ($foundElements as $matchedElement) { |
|
39 | + //Check to see whether this node was matched by the not query |
|
40 | + if ($pseudoMatcher->matches($matchedElement) && $element->isSameNode($matchedElement)) return true; |
|
41 | + } |
|
42 | + return false; |
|
43 | + } |
|
44 | 44 | } |
@@ -15,7 +15,9 @@ discard block |
||
15 | 15 | } |
16 | 16 | |
17 | 17 | public function match($name, $args, \DomElement $element) { |
18 | - if ($name !== 'not') return true; |
|
18 | + if ($name !== 'not') { |
|
19 | + return true; |
|
20 | + } |
|
19 | 21 | |
20 | 22 | $xpath = new \DomXpath($element->ownerDocument); |
21 | 23 | return $this->notElement($args, $xpath, $element); |
@@ -28,7 +30,9 @@ discard block |
||
28 | 30 | $xpathString = $this->cssToXpath->getXpath($tokenizer->getTokens()); |
29 | 31 | $pseudo = $this->cssToXpath->getPseudo($tokenizer->getTokens()); |
30 | 32 | $pseudoMatcher = $this->config->createPseudoMatcher($pseudo); |
31 | - if ($this->matches($xpath->query($xpathString), $element, $pseudoMatcher)) return false; |
|
33 | + if ($this->matches($xpath->query($xpathString), $element, $pseudoMatcher)) { |
|
34 | + return false; |
|
35 | + } |
|
32 | 36 | } |
33 | 37 | return true; |
34 | 38 | } |
@@ -37,7 +41,9 @@ discard block |
||
37 | 41 | //Find all nodes matched by the expressions in the brackets :not(EXPR) |
38 | 42 | foreach ($foundElements as $matchedElement) { |
39 | 43 | //Check to see whether this node was matched by the not query |
40 | - if ($pseudoMatcher->matches($matchedElement) && $element->isSameNode($matchedElement)) return true; |
|
44 | + if ($pseudoMatcher->matches($matchedElement) && $element->isSameNode($matchedElement)) { |
|
45 | + return true; |
|
46 | + } |
|
41 | 47 | } |
42 | 48 | return false; |
43 | 49 | } |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | private $rules; |
11 | 11 | private $configLine; |
12 | 12 | private $file; |
13 | - private $filePath; |
|
13 | + private $filePath; |
|
14 | 14 | private $line; |
15 | 15 | private $valueParser; |
16 | 16 | private $pseudoMatcher; |
@@ -18,11 +18,11 @@ discard block |
||
18 | 18 | private $functionSet; |
19 | 19 | |
20 | 20 | public function __construct(array $rules, &$configLine, $file, $line, PseudoMatcher $pseudoMatcher, |
21 | - \Transphporm\Parser\Value $valueParser, \Transphporm\FunctionSet $functionSet, \Transphporm\FilePath $filePath) { |
|
21 | + \Transphporm\Parser\Value $valueParser, \Transphporm\FunctionSet $functionSet, \Transphporm\FilePath $filePath) { |
|
22 | 22 | $this->rules = $rules; |
23 | 23 | $this->configLine = &$configLine; |
24 | 24 | $this->file = $file; |
25 | - $this->filePath = $filePath; |
|
25 | + $this->filePath = $filePath; |
|
26 | 26 | $this->line = $line; |
27 | 27 | $this->valueParser = $valueParser; |
28 | 28 | $this->pseudoMatcher = $pseudoMatcher; |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | |
32 | 32 | public function run(\DomElement $element) { |
33 | 33 | //Set the baseDir so that all files for this rule are relative to the file it came from |
34 | - if ($this->file !== null) $this->filePath->setBaseDir(dirname(realpath($this->file))); |
|
34 | + if ($this->file !== null) $this->filePath->setBaseDir(dirname(realpath($this->file))); |
|
35 | 35 | $this->functionSet->setElement($element); |
36 | 36 | $this->configLine = $this->line; |
37 | 37 | try { |
@@ -31,15 +31,18 @@ discard block |
||
31 | 31 | |
32 | 32 | public function run(\DomElement $element) { |
33 | 33 | //Set the baseDir so that all files for this rule are relative to the file it came from |
34 | - if ($this->file !== null) $this->filePath->setBaseDir(dirname(realpath($this->file))); |
|
34 | + if ($this->file !== null) { |
|
35 | + $this->filePath->setBaseDir(dirname(realpath($this->file))); |
|
36 | + } |
|
35 | 37 | $this->functionSet->setElement($element); |
36 | 38 | $this->configLine = $this->line; |
37 | 39 | try { |
38 | 40 | //Don't run if there's a pseudo element like nth-child() and this element doesn't match it |
39 | - if (!$this->pseudoMatcher->matches($element)) return; |
|
41 | + if (!$this->pseudoMatcher->matches($element)) { |
|
42 | + return; |
|
43 | + } |
|
40 | 44 | $this->callProperties($element); |
41 | - } |
|
42 | - catch (\Transphporm\RunException $e) { |
|
45 | + } catch (\Transphporm\RunException $e) { |
|
43 | 46 | throw new \Transphporm\Exception($e, $this->file, $this->line); |
44 | 47 | } |
45 | 48 | } |
@@ -50,7 +53,9 @@ discard block |
||
50 | 53 | private function callProperties($element) { |
51 | 54 | foreach ($this->rules as $name => $value) { |
52 | 55 | $result = $this->callProperty($name, $element, $this->getArgs($value)); |
53 | - if ($result === false) break; |
|
56 | + if ($result === false) { |
|
57 | + break; |
|
58 | + } |
|
54 | 59 | } |
55 | 60 | } |
56 | 61 | private function getArgs($value) { |
@@ -65,9 +70,10 @@ discard block |
||
65 | 70 | if (isset($this->properties[$name])) { |
66 | 71 | try { |
67 | 72 | return $this->properties[$name]->run($value, $element, $this->rules, $this->pseudoMatcher, $this->properties); |
68 | - } |
|
69 | - catch (\Exception $e) { |
|
70 | - if ($e instanceof \Transphporm\RunException) throw $e; |
|
73 | + } catch (\Exception $e) { |
|
74 | + if ($e instanceof \Transphporm\RunException) { |
|
75 | + throw $e; |
|
76 | + } |
|
71 | 77 | throw new \Transphporm\RunException(\Transphporm\Exception::PROPERTY, $name, $e); |
72 | 78 | } |
73 | 79 | } |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | /** Converts $val into a \DateTime object if it's not already */ |
17 | 17 | private function getDate($val) { |
18 | 18 | $tz = new \DateTimeZone($this->locale['timezone']); |
19 | - $date = $val instanceof \DateTimeInterface ? $val : new \DateTime($val, $tz); |
|
19 | + $date = $val instanceof \DateTimeInterface ? $val : new \DateTime($val, $tz); |
|
20 | 20 | $date->setTimeZone($tz); |
21 | 21 | return $date; |
22 | 22 | } |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | |
36 | 36 | /** Formats \DateTime as Date and Time using formats from $locale */ |
37 | 37 | public function dateTime($val) { |
38 | - return $this->date($val, $this->locale['date_format'] . ' ' . $this->locale['time_format']); |
|
38 | + return $this->date($val, $this->locale['date_format'].' '.$this->locale['time_format']); |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | /** Generates relative time offsets based on system clock. e.g "10 minutes ago" or "In 6 months" |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | $diff = $now->diff($date); |
48 | 48 | |
49 | 49 | |
50 | - $diffDays = $diff->invert === 1 ? $diff->days : 0- $diff->days; |
|
50 | + $diffDays = $diff->invert === 1 ? $diff->days : 0-$diff->days; |
|
51 | 51 | |
52 | 52 | if ($diffDays !== 0) return $this->dayOffset($diffDays); |
53 | 53 | else return $this->timeOffset($diff); |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | |
76 | 76 | /** Gets date ranges to represent uses of weeks/months/days/etc */ |
77 | 77 | private function getRanges($strings) { |
78 | - $ranges = [ |
|
78 | + $ranges = [ |
|
79 | 79 | [1, 1, $strings['yesterday'], 1, ''], |
80 | 80 | [1, 13, $strings['past'], 1, 'days'], |
81 | 81 | [13, 28, $strings['past'], 7, 'weeks'], |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | |
95 | 95 | /** Converts "week" to "weeks", "month" to "months" etc when plural is required using language from $locale */ |
96 | 96 | private function getPlural($strings, $num, $interval) { |
97 | - if ($interval !== '') return $num == 1 ? $strings[$interval . '_singular'] : $strings[$interval . '_plural']; |
|
97 | + if ($interval !== '') return $num == 1 ? $strings[$interval.'_singular'] : $strings[$interval.'_plural']; |
|
98 | 98 | else return ''; |
99 | 99 | } |
100 | 100 |
@@ -92,10 +92,10 @@ |
||
92 | 92 | return $ranges; |
93 | 93 | } |
94 | 94 | |
95 | - private function add2DayRanges(&$ranges, $property, $when) { |
|
96 | - $rangeVal = $when === "before" ? 2 : -2; |
|
97 | - array_unshift($ranges, [$rangeVal, $rangeVal, $property, 1, '']); |
|
98 | - } |
|
95 | + private function add2DayRanges(&$ranges, $property, $when) { |
|
96 | + $rangeVal = $when === "before" ? 2 : -2; |
|
97 | + array_unshift($ranges, [$rangeVal, $rangeVal, $property, 1, '']); |
|
98 | + } |
|
99 | 99 | |
100 | 100 | /** Converts "week" to "weeks", "month" to "months" etc when plural is required using language from $locale */ |
101 | 101 | private function getPlural($strings, $num, $interval) { |
@@ -49,8 +49,11 @@ discard block |
||
49 | 49 | |
50 | 50 | $diffDays = $diff->invert === 1 ? $diff->days : 0- $diff->days; |
51 | 51 | |
52 | - if ($diffDays !== 0) return $this->dayOffset($diffDays); |
|
53 | - else return $this->timeOffset($diff); |
|
52 | + if ($diffDays !== 0) { |
|
53 | + return $this->dayOffset($diffDays); |
|
54 | + } else { |
|
55 | + return $this->timeOffset($diff); |
|
56 | + } |
|
54 | 57 | } |
55 | 58 | |
56 | 59 | /** Calculates offset in hours/minutes/seconds */ |
@@ -87,8 +90,12 @@ discard block |
||
87 | 90 | [-365, -28, $strings['future'], 28, 'months'], |
88 | 91 | [-999999, -365, $strings['future'], 365, 'years'], |
89 | 92 | ]; |
90 | - if (isset($strings['day_before_yesterday'])) $this->add2DayRanges($ranges, $strings['day_before_yesterday'], "before"); |
|
91 | - if (isset($strings['day_after_tomorrow'])) $this->add2DayRanges($ranges, $strings['day_after_tomorrow'], "after"); |
|
93 | + if (isset($strings['day_before_yesterday'])) { |
|
94 | + $this->add2DayRanges($ranges, $strings['day_before_yesterday'], "before"); |
|
95 | + } |
|
96 | + if (isset($strings['day_after_tomorrow'])) { |
|
97 | + $this->add2DayRanges($ranges, $strings['day_after_tomorrow'], "after"); |
|
98 | + } |
|
92 | 99 | return $ranges; |
93 | 100 | } |
94 | 101 | |
@@ -99,8 +106,11 @@ discard block |
||
99 | 106 | |
100 | 107 | /** Converts "week" to "weeks", "month" to "months" etc when plural is required using language from $locale */ |
101 | 108 | private function getPlural($strings, $num, $interval) { |
102 | - if ($interval !== '') return $num == 1 ? $strings[$interval . '_singular'] : $strings[$interval . '_plural']; |
|
103 | - else return ''; |
|
109 | + if ($interval !== '') { |
|
110 | + return $num == 1 ? $strings[$interval . '_singular'] : $strings[$interval . '_plural']; |
|
111 | + } else { |
|
112 | + return ''; |
|
113 | + } |
|
104 | 114 | } |
105 | 115 | |
106 | 116 | /** Calculates offset in days/weeks/month/years */ |
@@ -69,7 +69,7 @@ |
||
69 | 69 | |
70 | 70 | public function extract($last, $autoLookup, $traversing) { |
71 | 71 | $value = $this->read($last); |
72 | - if ($value !== null && ($autoLookup || $traversing) ) { |
|
72 | + if ($value !== null && ($autoLookup || $traversing)) { |
|
73 | 73 | return $value; |
74 | 74 | } |
75 | 75 | throw new \UnexpectedValueException('Not found'); |
@@ -15,13 +15,17 @@ discard block |
||
15 | 15 | |
16 | 16 | //Read $key from array, $this->data = $this->data[$key] but also works for objects |
17 | 17 | private function traverseInto($key) { |
18 | - if (isset($this->data->{$key})) $this->data = $this->data->{$key}; |
|
19 | - else if ($this->isArray() && isset($this->data[$key])) $this->data = $this->data[$key]; |
|
18 | + if (isset($this->data->{$key})) { |
|
19 | + $this->data = $this->data->{$key}; |
|
20 | + } else if ($this->isArray() && isset($this->data[$key])) { |
|
21 | + $this->data = $this->data[$key]; |
|
22 | + } |
|
20 | 23 | } |
21 | 24 | |
22 | 25 | public function traverse($key, $result) { |
23 | - if ($key !== null) $this->traverseInto($key); |
|
24 | - else { |
|
26 | + if ($key !== null) { |
|
27 | + $this->traverseInto($key); |
|
28 | + } else { |
|
25 | 29 | //But if the key is null, replace the data structure with the result of the last function call |
26 | 30 | $lastResult = $result->pop(); |
27 | 31 | if ($lastResult) { |
@@ -41,10 +45,14 @@ discard block |
||
41 | 45 | |
42 | 46 | public function read($value) { |
43 | 47 | if ($this->isArray()) { |
44 | - if (isset($this->data[$value])) return $this->data[$value]; |
|
48 | + if (isset($this->data[$value])) { |
|
49 | + return $this->data[$value]; |
|
50 | + } |
|
51 | + } else if (isset($this->data->$value)) { |
|
52 | + return $this->data->$value; |
|
53 | + } else { |
|
54 | + return null; |
|
45 | 55 | } |
46 | - else if (isset($this->data->$value)) return $this->data->$value; |
|
47 | - else return null; |
|
48 | 56 | } |
49 | 57 | |
50 | 58 | public function call($func, $args) { |
@@ -57,14 +65,20 @@ discard block |
||
57 | 65 | |
58 | 66 | public function parseNested($parser, $token, $funcName) { |
59 | 67 | $args = $parser->parseTokens($token['value'], $this->data); |
60 | - if ($args[0] === $this->data) $args = []; |
|
68 | + if ($args[0] === $this->data) { |
|
69 | + $args = []; |
|
70 | + } |
|
61 | 71 | return $this->callFuncOnObject($this->data, $funcName, $args); |
62 | 72 | } |
63 | 73 | |
64 | 74 | private function callFuncOnObject($obj, $func, $args) { |
65 | - if (isset($obj->$func) && is_callable($obj->$func)) return call_user_func_array($obj->$func, $args); |
|
66 | - else if (is_callable([$obj, $func])) return call_user_func_array([$obj, $func], $args); |
|
67 | - else return false; |
|
75 | + if (isset($obj->$func) && is_callable($obj->$func)) { |
|
76 | + return call_user_func_array($obj->$func, $args); |
|
77 | + } else if (is_callable([$obj, $func])) { |
|
78 | + return call_user_func_array([$obj, $func], $args); |
|
79 | + } else { |
|
80 | + return false; |
|
81 | + } |
|
68 | 82 | } |
69 | 83 | |
70 | 84 | public function extract($last, $autoLookup, $traversing) { |
@@ -14,15 +14,15 @@ |
||
14 | 14 | |
15 | 15 | public function getFilePath($filePath) { |
16 | 16 | if (is_file($filePath)) return $filePath; |
17 | - else if (is_file($this->baseDir . DIRECTORY_SEPARATOR . $filePath)) return $this->baseDir . DIRECTORY_SEPARATOR . $filePath; |
|
17 | + else if (is_file($this->baseDir.DIRECTORY_SEPARATOR.$filePath)) return $this->baseDir.DIRECTORY_SEPARATOR.$filePath; |
|
18 | 18 | else return $this->loadFromPaths($filePath); |
19 | 19 | } |
20 | 20 | |
21 | 21 | private function loadFromPaths($filePath) { |
22 | 22 | foreach ($this->paths as $path) { |
23 | - if (is_file($path . DIRECTORY_SEPARATOR . $filePath)) return $path . DIRECTORY_SEPARATOR . $filePath; |
|
23 | + if (is_file($path.DIRECTORY_SEPARATOR.$filePath)) return $path.DIRECTORY_SEPARATOR.$filePath; |
|
24 | 24 | } |
25 | 25 | |
26 | - throw new \Exception($filePath . ' not found in include path: ' . implode(';', $this->paths)); |
|
26 | + throw new \Exception($filePath.' not found in include path: '.implode(';', $this->paths)); |
|
27 | 27 | } |
28 | 28 | } |
@@ -13,14 +13,20 @@ |
||
13 | 13 | } |
14 | 14 | |
15 | 15 | public function getFilePath($filePath) { |
16 | - if (is_file($filePath)) return $filePath; |
|
17 | - else if (is_file($this->baseDir . DIRECTORY_SEPARATOR . $filePath)) return $this->baseDir . DIRECTORY_SEPARATOR . $filePath; |
|
18 | - else return $this->loadFromPaths($filePath); |
|
16 | + if (is_file($filePath)) { |
|
17 | + return $filePath; |
|
18 | + } else if (is_file($this->baseDir . DIRECTORY_SEPARATOR . $filePath)) { |
|
19 | + return $this->baseDir . DIRECTORY_SEPARATOR . $filePath; |
|
20 | + } else { |
|
21 | + return $this->loadFromPaths($filePath); |
|
22 | + } |
|
19 | 23 | } |
20 | 24 | |
21 | 25 | private function loadFromPaths($filePath) { |
22 | 26 | foreach ($this->paths as $path) { |
23 | - if (is_file($path . DIRECTORY_SEPARATOR . $filePath)) return $path . DIRECTORY_SEPARATOR . $filePath; |
|
27 | + if (is_file($path . DIRECTORY_SEPARATOR . $filePath)) { |
|
28 | + return $path . DIRECTORY_SEPARATOR . $filePath; |
|
29 | + } |
|
24 | 30 | } |
25 | 31 | |
26 | 32 | throw new \Exception($filePath . ' not found in include path: ' . implode(';', $this->paths)); |