@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | } |
52 | 52 | |
53 | 53 | private function getSheetLoader() { |
54 | - $tssRules = is_file((string)$this->tss) ? new SheetLoader\TSSFile($this->tss, $this->filePath, $this->cache, $this->time) : new SheetLoader\TSSString($this->tss, $this->filePath); |
|
54 | + $tssRules = is_file((string) $this->tss) ? new SheetLoader\TSSFile($this->tss, $this->filePath, $this->cache, $this->time) : new SheetLoader\TSSString($this->tss, $this->filePath); |
|
55 | 55 | return new SheetLoader\SheetLoader($this->cache, $this->filePath, $tssRules, $this->time); |
56 | 56 | } |
57 | 57 | |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | 'headers' => array_merge($result['headers'], $headers), |
73 | 73 | 'body' => $this->doPostProcessing($template)->output($document) |
74 | 74 | ]; |
75 | - $this->cache->write($tssCache->getCacheKey($data) . $this->template, $result); |
|
75 | + $this->cache->write($tssCache->getCacheKey($data).$this->template, $result); |
|
76 | 76 | } |
77 | 77 | unset($result['cache'], $result['renderTime']); |
78 | 78 | return (object) $result; |
@@ -82,10 +82,10 @@ discard block |
||
82 | 82 | $elementData = new \Transphporm\Hook\ElementData(new \SplObjectStorage(), $data); |
83 | 83 | $functionSet = new FunctionSet($elementData); |
84 | 84 | //To be a valid XML document it must have a root element, automatically wrap it in <template> to ensure it does |
85 | - $template = new Template($this->isValidDoc($body) ? str_ireplace('<!doctype', '<!DOCTYPE', $body) : '<template>' . $body . '</template>' ); |
|
85 | + $template = new Template($this->isValidDoc($body) ? str_ireplace('<!doctype', '<!DOCTYPE', $body) : '<template>'.$body.'</template>'); |
|
86 | 86 | |
87 | 87 | $valueParser = new Parser\Value($functionSet); |
88 | - $this->config = new Config($functionSet, $valueParser, $elementData, new Hook\Formatter(), new Parser\CssToXpath($functionSet, $template->getPrefix(), md5((string)$this->tss)), $this->filePath, $headers); |
|
88 | + $this->config = new Config($functionSet, $valueParser, $elementData, new Hook\Formatter(), new Parser\CssToXpath($functionSet, $template->getPrefix(), md5((string) $this->tss)), $this->filePath, $headers); |
|
89 | 89 | |
90 | 90 | foreach ($this->modules as $module) $module->load($this->config); |
91 | 91 | return $template; |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | } |
107 | 107 | |
108 | 108 | private function loadTemplateFromFile($file) { |
109 | - $xml = $this->cache->load($this->cacheKey . $file, filemtime($file)); |
|
109 | + $xml = $this->cache->load($this->cacheKey.$file, filemtime($file)); |
|
110 | 110 | return $xml ? $xml : ['cache' => file_get_contents($file) ?: "", 'headers' => []]; |
111 | 111 | } |
112 | 112 |
@@ -28,7 +28,9 @@ discard block |
||
28 | 28 | $this->cache = new Cache(new \ArrayObject()); |
29 | 29 | $this->filePath = new FilePath(); |
30 | 30 | $modules = is_array($modules) ? $modules : $this->defaultModules; |
31 | - foreach ($modules as $module) $this->loadModule(new $module); |
|
31 | + foreach ($modules as $module) { |
|
32 | + $this->loadModule(new $module); |
|
33 | + } |
|
32 | 34 | } |
33 | 35 | |
34 | 36 | //Allow setting the time used by Transphporm for caching. This is for testing purposes |
@@ -87,7 +89,9 @@ discard block |
||
87 | 89 | $valueParser = new Parser\Value($functionSet); |
88 | 90 | $this->config = new Config($functionSet, $valueParser, $elementData, new Hook\Formatter(), new Parser\CssToXpath($functionSet, $template->getPrefix(), md5((string)$this->tss)), $this->filePath, $headers); |
89 | 91 | |
90 | - foreach ($this->modules as $module) $module->load($this->config); |
|
92 | + foreach ($this->modules as $module) { |
|
93 | + $module->load($this->config); |
|
94 | + } |
|
91 | 95 | return $template; |
92 | 96 | } |
93 | 97 | |
@@ -101,7 +105,9 @@ discard block |
||
101 | 105 | //Load a template, firstly check if it's a file or a valid string |
102 | 106 | private function loadTemplate() { |
103 | 107 | $result = ['cache' => $this->template, 'headers' => []]; |
104 | - if (strpos($this->template, "\n") === false && is_file($this->template)) $result = $this->loadTemplateFromFile($this->template); |
|
108 | + if (strpos($this->template, "\n") === false && is_file($this->template)) { |
|
109 | + $result = $this->loadTemplateFromFile($this->template); |
|
110 | + } |
|
105 | 111 | return $result; |
106 | 112 | } |
107 | 113 | |
@@ -120,6 +126,8 @@ discard block |
||
120 | 126 | |
121 | 127 | public function __destruct() { |
122 | 128 | //Required hack as DomXPath can only register static functions clear the statically stored instance to avoid memory leaks |
123 | - if (isset($this->config)) $this->config->getCssToXpath()->cleanup(); |
|
129 | + if (isset($this->config)) { |
|
130 | + $this->config->getCssToXpath()->cleanup(); |
|
131 | + } |
|
124 | 132 | } |
125 | 133 | } |
@@ -6,39 +6,39 @@ |
||
6 | 6 | * @version 1.2 */ |
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(): array { |
|
18 | - return $this->tokens->current(); |
|
19 | - } |
|
17 | + public function current(): array { |
|
18 | + return $this->tokens->current(); |
|
19 | + } |
|
20 | 20 | |
21 | - public function key(): int { |
|
22 | - return $this->tokens->key(); |
|
23 | - } |
|
21 | + public function key(): int { |
|
22 | + return $this->tokens->key(); |
|
23 | + } |
|
24 | 24 | |
25 | - public function valid(): bool { |
|
26 | - return $this->tokens->valid(); |
|
27 | - } |
|
25 | + public function valid(): bool { |
|
26 | + return $this->tokens->valid(); |
|
27 | + } |
|
28 | 28 | |
29 | - public function next(): void { |
|
30 | - do { |
|
31 | - $this->tokens->next(); |
|
32 | - } |
|
33 | - while ($this->shouldContinue()); |
|
34 | - } |
|
29 | + public function next(): void { |
|
30 | + do { |
|
31 | + $this->tokens->next(); |
|
32 | + } |
|
33 | + while ($this->shouldContinue()); |
|
34 | + } |
|
35 | 35 | |
36 | - public function rewind(): void { |
|
37 | - $this->tokens->rewind(); |
|
38 | - while ($this->shouldContinue()) $this->tokens->next(); |
|
39 | - } |
|
36 | + public function rewind(): void { |
|
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(): void { |
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() { |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | |
53 | 53 | public function next() { |
54 | 54 | $this->pos++; |
55 | - return $this->pos < strlen((string)$this->str); |
|
55 | + return $this->pos < strlen((string) $this->str); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | public function reset() { |
@@ -61,21 +61,21 @@ discard block |
||
61 | 61 | } |
62 | 62 | |
63 | 63 | public function read($offset = 0) { |
64 | - return $this->str[$this->pos + $offset]; |
|
64 | + return $this->str[$this->pos+$offset]; |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | public function identifyChar($offset = 0) { |
68 | - $chr = $this->str[$this->pos + $offset]; |
|
68 | + $chr = $this->str[$this->pos+$offset]; |
|
69 | 69 | if (!empty($this->chars[$chr])) return $this->chars[$chr]; |
70 | 70 | else return Tokenizer::NAME; |
71 | 71 | } |
72 | 72 | |
73 | 73 | public function has($offset = 0) { |
74 | - return isset($this->str[$this->pos + $offset]); |
|
74 | + return isset($this->str[$this->pos+$offset]); |
|
75 | 75 | } |
76 | 76 | |
77 | 77 | public function pos($str) { |
78 | - $pos = strpos($this->str, $str, $this->pos); |
|
78 | + $pos = strpos($this->str, $str, $this->pos); |
|
79 | 79 | return $pos ? $pos-$this->pos : false; |
80 | 80 | } |
81 | 81 | |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | } |
89 | 89 | |
90 | 90 | public function extractString($offset = 0) { |
91 | - $pos = $this->pos + $offset; |
|
91 | + $pos = $this->pos+$offset; |
|
92 | 92 | $char = $this->str[$pos]; |
93 | 93 | $end = strpos($this->str, $char, $pos+1); |
94 | 94 | while ($end !== false && $this->str[$end-1] == '\\') $end = strpos($this->str, $char, $end+1); |
@@ -15,8 +15,8 @@ |
||
15 | 15 | |
16 | 16 | private function getLocale() { |
17 | 17 | if (is_array($this->locale)) return $this->locale; |
18 | - else if (strlen((string)$this->locale) > 0) return json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . '../Formatter' . DIRECTORY_SEPARATOR . 'Locale' . DIRECTORY_SEPARATOR . $this->locale . '.json'), true); |
|
19 | - else return json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . '../Formatter' . DIRECTORY_SEPARATOR . 'Locale' . DIRECTORY_SEPARATOR . 'enGB.json'), true); |
|
18 | + else if (strlen((string) $this->locale) > 0) return json_decode(file_get_contents(__DIR__.DIRECTORY_SEPARATOR.'../Formatter'.DIRECTORY_SEPARATOR.'Locale'.DIRECTORY_SEPARATOR.$this->locale.'.json'), true); |
|
19 | + else return json_decode(file_get_contents(__DIR__.DIRECTORY_SEPARATOR.'../Formatter'.DIRECTORY_SEPARATOR.'Locale'.DIRECTORY_SEPARATOR.'enGB.json'), true); |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | public function load(\Transphporm\Config $config) { |
@@ -14,9 +14,13 @@ |
||
14 | 14 | } |
15 | 15 | |
16 | 16 | private function getLocale() { |
17 | - if (is_array($this->locale)) return $this->locale; |
|
18 | - else if (strlen((string)$this->locale) > 0) return json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . '../Formatter' . DIRECTORY_SEPARATOR . 'Locale' . DIRECTORY_SEPARATOR . $this->locale . '.json'), true); |
|
19 | - else return json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . '../Formatter' . DIRECTORY_SEPARATOR . 'Locale' . DIRECTORY_SEPARATOR . 'enGB.json'), true); |
|
17 | + if (is_array($this->locale)) { |
|
18 | + return $this->locale; |
|
19 | + } else if (strlen((string)$this->locale) > 0) { |
|
20 | + return json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . '../Formatter' . DIRECTORY_SEPARATOR . 'Locale' . DIRECTORY_SEPARATOR . $this->locale . '.json'), true); |
|
21 | + } else { |
|
22 | + return json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . '../Formatter' . DIRECTORY_SEPARATOR . 'Locale' . DIRECTORY_SEPARATOR . 'enGB.json'), true); |
|
23 | + } |
|
20 | 24 | } |
21 | 25 | |
22 | 26 | public function load(\Transphporm\Config $config) { |
@@ -14,7 +14,9 @@ discard block |
||
14 | 14 | } |
15 | 15 | |
16 | 16 | public function run(array $values, \DomElement $element, array $rules, \Transphporm\Hook\PseudoMatcher $pseudoMatcher, array $properties = []) { |
17 | - if (!$this->shouldRun($element)) return false; |
|
17 | + if (!$this->shouldRun($element)) { |
|
18 | + return false; |
|
19 | + } |
|
18 | 20 | |
19 | 21 | $values = $this->formatter->format($values, $rules); |
20 | 22 | |
@@ -25,14 +27,17 @@ discard block |
||
25 | 27 | if ($this->getContentMode($rules) === 'replace') { |
26 | 28 | $contentReplace = new ContentReplace($this); |
27 | 29 | $contentReplace->replaceContent($element, $values); |
30 | + } else { |
|
31 | + $this->appendContent($element, $values); |
|
28 | 32 | } |
29 | - else $this->appendContent($element, $values); |
|
30 | 33 | } |
31 | 34 | } |
32 | 35 | |
33 | 36 | private function shouldRun($element) { |
34 | 37 | do { |
35 | - if ($element->getAttribute('transphporm') == 'includedtemplate') return false; |
|
38 | + if ($element->getAttribute('transphporm') == 'includedtemplate') { |
|
39 | + return false; |
|
40 | + } |
|
36 | 41 | } |
37 | 42 | while (($element = $element->parentNode) instanceof \DomElement); |
38 | 43 | return true; |
@@ -59,9 +64,10 @@ discard block |
||
59 | 64 | public function getNode($node, $document) { |
60 | 65 | foreach ($node as $n) { |
61 | 66 | if (is_array($n)) { |
62 | - foreach ($this->getNode($n, $document) as $new) yield $new; |
|
63 | - } |
|
64 | - else { |
|
67 | + foreach ($this->getNode($n, $document) as $new) { |
|
68 | + yield $new; |
|
69 | + } |
|
70 | + } else { |
|
65 | 71 | yield $this->convertNode($n, $document); |
66 | 72 | } |
67 | 73 | } |
@@ -70,9 +76,10 @@ discard block |
||
70 | 76 | private function convertNode($node, $document) { |
71 | 77 | if ($node instanceof \DomElement || $node instanceof \DOMComment) { |
72 | 78 | $new = $document->importNode($node, true); |
73 | - } |
|
74 | - else { |
|
75 | - if ($node instanceof \DomText) $node = $node->nodeValue; |
|
79 | + } else { |
|
80 | + if ($node instanceof \DomText) { |
|
81 | + $node = $node->nodeValue; |
|
82 | + } |
|
76 | 83 | $new = $document->createElement('text'); |
77 | 84 | |
78 | 85 | $new->appendChild($document->createTextNode($node !== null ? $node : '')); |
@@ -89,6 +96,8 @@ discard block |
||
89 | 96 | } |
90 | 97 | |
91 | 98 | private function removeAllChildren($element) { |
92 | - while ($element->hasChildNodes()) $element->removeChild($element->firstChild); |
|
99 | + while ($element->hasChildNodes()) { |
|
100 | + $element->removeChild($element->firstChild); |
|
101 | + } |
|
93 | 102 | } |
94 | 103 | } |
@@ -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((string)$val, $tz); |
|
19 | + $date = $val instanceof \DateTimeInterface ? $val : new \DateTime((string) $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" |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | $date->add(new \DateInterval("PT${secondsToAdd}S")); |
50 | 50 | |
51 | 51 | $diff = $now->diff($date); |
52 | - $diffDays = $diff->invert === 1 ? $diff->days : 0- $diff->days; |
|
52 | + $diffDays = $diff->invert === 1 ? $diff->days : 0-$diff->days; |
|
53 | 53 | |
54 | 54 | if ($diffDays !== 0) return $this->dayOffset($diffDays); |
55 | 55 | else return $this->timeOffset($diff); |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | |
78 | 78 | /** Gets date ranges to represent uses of weeks/months/days/etc */ |
79 | 79 | private function getRanges($strings) { |
80 | - $ranges = [ |
|
80 | + $ranges = [ |
|
81 | 81 | [1, 1, $strings['yesterday'], 1, ''], |
82 | 82 | [1, 13, $strings['past'], 1, 'days'], |
83 | 83 | [13, 28, $strings['past'], 7, 'weeks'], |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | |
102 | 102 | /** Converts "week" to "weeks", "month" to "months" etc when plural is required using language from $locale */ |
103 | 103 | private function getPlural($strings, $num, $interval) { |
104 | - if ($interval !== '') return $num == 1 ? $strings[$interval . '_singular'] : $strings[$interval . '_plural']; |
|
104 | + if ($interval !== '') return $num == 1 ? $strings[$interval.'_singular'] : $strings[$interval.'_plural']; |
|
105 | 105 | else return ''; |
106 | 106 | } |
107 | 107 |
@@ -51,8 +51,11 @@ discard block |
||
51 | 51 | $diff = $now->diff($date); |
52 | 52 | $diffDays = $diff->invert === 1 ? $diff->days : 0- $diff->days; |
53 | 53 | |
54 | - if ($diffDays !== 0) return $this->dayOffset($diffDays); |
|
55 | - else return $this->timeOffset($diff); |
|
54 | + if ($diffDays !== 0) { |
|
55 | + return $this->dayOffset($diffDays); |
|
56 | + } else { |
|
57 | + return $this->timeOffset($diff); |
|
58 | + } |
|
56 | 59 | } |
57 | 60 | |
58 | 61 | /** Calculates offset in hours/minutes/seconds */ |
@@ -89,8 +92,12 @@ discard block |
||
89 | 92 | [-365, -28, $strings['future'], 28, 'months'], |
90 | 93 | [-999999, -365, $strings['future'], 365, 'years'], |
91 | 94 | ]; |
92 | - if (isset($strings['day_before_yesterday'])) $this->add2DayRanges($ranges, $strings['day_before_yesterday'], "before"); |
|
93 | - if (isset($strings['day_after_tomorrow'])) $this->add2DayRanges($ranges, $strings['day_after_tomorrow'], "after"); |
|
95 | + if (isset($strings['day_before_yesterday'])) { |
|
96 | + $this->add2DayRanges($ranges, $strings['day_before_yesterday'], "before"); |
|
97 | + } |
|
98 | + if (isset($strings['day_after_tomorrow'])) { |
|
99 | + $this->add2DayRanges($ranges, $strings['day_after_tomorrow'], "after"); |
|
100 | + } |
|
94 | 101 | return $ranges; |
95 | 102 | } |
96 | 103 | |
@@ -101,8 +108,11 @@ discard block |
||
101 | 108 | |
102 | 109 | /** Converts "week" to "weeks", "month" to "months" etc when plural is required using language from $locale */ |
103 | 110 | private function getPlural($strings, $num, $interval) { |
104 | - if ($interval !== '') return $num == 1 ? $strings[$interval . '_singular'] : $strings[$interval . '_plural']; |
|
105 | - else return ''; |
|
111 | + if ($interval !== '') { |
|
112 | + return $num == 1 ? $strings[$interval . '_singular'] : $strings[$interval . '_plural']; |
|
113 | + } else { |
|
114 | + return ''; |
|
115 | + } |
|
106 | 116 | } |
107 | 117 | |
108 | 118 | /** Calculates offset in days/weeks/month/years */ |