@@ -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 | } |
@@ -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() { |
@@ -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 | } |