@@ -8,11 +8,15 @@ |
||
8 | 8 | } |
9 | 9 | |
10 | 10 | public function format($value, $rules) { |
11 | - if (!isset($rules['format'])) return $value; |
|
11 | + if (!isset($rules['format'])) { |
|
12 | + return $value; |
|
13 | + } |
|
12 | 14 | $format = new \Transphporm\StringExtractor($rules['format']); |
13 | 15 | $options = explode(' ', $format); |
14 | 16 | $functionName = array_shift($options); |
15 | - foreach ($options as &$f) $f = trim($format->rebuild($f), '"'); |
|
17 | + foreach ($options as &$f) { |
|
18 | + $f = trim($format->rebuild($f), '"'); |
|
19 | + } |
|
16 | 20 | |
17 | 21 | return $this->processFormat($options, $functionName, $value); |
18 | 22 | } |
@@ -64,22 +64,29 @@ discard block |
||
64 | 64 | $node = $element->ownerDocument->importNode($node, true); |
65 | 65 | $element->appendChild($node); |
66 | 66 | } |
67 | + } else { |
|
68 | + $element->appendChild($element->ownerDocument->createTextNode(implode('', $content))); |
|
67 | 69 | } |
68 | - else $element->appendChild($element->ownerDocument->createTextNode(implode('', $content))); |
|
69 | 70 | } |
70 | 71 | |
71 | 72 | private function removeAllChildren($element) { |
72 | - while ($element->hasChildNodes()) $element->removeChild($element->firstChild); |
|
73 | + while ($element->hasChildNodes()) { |
|
74 | + $element->removeChild($element->firstChild); |
|
75 | + } |
|
73 | 76 | } |
74 | 77 | |
75 | 78 | private function createHook($newRules, $rule) { |
76 | 79 | $hook = new Rule($newRules, $rule->getPseudoMatcher(), $this->data); |
77 | - foreach ($rule->getProperties() as $obj) $hook->registerProperties($obj); |
|
80 | + foreach ($rule->getProperties() as $obj) { |
|
81 | + $hook->registerProperties($obj); |
|
82 | + } |
|
78 | 83 | return $hook; |
79 | 84 | } |
80 | 85 | |
81 | 86 | public function repeat($value, $element, $rule) { |
82 | - if ($element->getAttribute('transphporm') === 'added') return $element->parentNode->removeChild($element); |
|
87 | + if ($element->getAttribute('transphporm') === 'added') { |
|
88 | + return $element->parentNode->removeChild($element); |
|
89 | + } |
|
83 | 90 | |
84 | 91 | foreach ($value as $key => $iteration) { |
85 | 92 | $clone = $element->cloneNode(true); |
@@ -103,8 +110,11 @@ discard block |
||
103 | 110 | } |
104 | 111 | |
105 | 112 | public function display($value, $element) { |
106 | - if (strtolower($value[0]) === 'none') $element->setAttribute('transphporm', 'remove'); |
|
107 | - else $element->setAttribute('transphporm', 'show'); |
|
113 | + if (strtolower($value[0]) === 'none') { |
|
114 | + $element->setAttribute('transphporm', 'remove'); |
|
115 | + } else { |
|
116 | + $element->setAttribute('transphporm', 'show'); |
|
117 | + } |
|
108 | 118 | } |
109 | 119 | |
110 | 120 | public function bind($value, $element) { |
@@ -41,7 +41,9 @@ discard block |
||
41 | 41 | |
42 | 42 | //Allow $time to be set via arguments to spoof time passage during tests |
43 | 43 | foreach ($this->getRules($template) as $rule) { |
44 | - if ($rule->shouldRun($this->time)) $this->executeTssRule($rule, $template, $data); |
|
44 | + if ($rule->shouldRun($this->time)) { |
|
45 | + $this->executeTssRule($rule, $template, $data); |
|
46 | + } |
|
45 | 47 | } |
46 | 48 | |
47 | 49 | $result = ['body' => $template->output($document), 'headers' => array_merge($cachedOutput['headers'], $headers)]; |
@@ -61,7 +63,9 @@ discard block |
||
61 | 63 | private function executeTssRule($rule, $template, $data) { |
62 | 64 | $rule->touch(); |
63 | 65 | $hook = new Hook\Rule($rule->properties, new Hook\PseudoMatcher($rule->pseudo, $data), $data); |
64 | - foreach ($this->registeredProperties as $properties) $hook->registerProperties($properties); |
|
66 | + foreach ($this->registeredProperties as $properties) { |
|
67 | + $hook->registerProperties($properties); |
|
68 | + } |
|
65 | 69 | $template->addHook($rule->query, $hook); |
66 | 70 | } |
67 | 71 | |
@@ -70,8 +74,9 @@ discard block |
||
70 | 74 | if (trim($this->template)[0] !== '<') { |
71 | 75 | $xml = $this->cache->load($this->template, filemtime($this->template)); |
72 | 76 | return $xml ? $xml : ['body' => file_get_contents($this->template), 'headers' => []]; |
77 | + } else { |
|
78 | + return ['body' => $this->template, 'headers' => []]; |
|
73 | 79 | } |
74 | - else return ['body' => $this->template, 'headers' => []]; |
|
75 | 80 | } |
76 | 81 | |
77 | 82 | //Load the TSS rules either from a file or as a string |
@@ -85,10 +90,14 @@ discard block |
||
85 | 90 | $key = $this->tss . $template->getPrefix() . $this->baseDir; |
86 | 91 | //Try to load the cached rules, if not set in the cache (or expired) parse the supplied sheet |
87 | 92 | $rules = $this->cache->load($key, filemtime($this->tss)); |
88 | - if (!$rules) return $this->cache->write($key, (new Sheet(file_get_contents($this->tss), $this->baseDir, $template->getPrefix()))->parse()); |
|
89 | - else return $rules; |
|
93 | + if (!$rules) { |
|
94 | + return $this->cache->write($key, (new Sheet(file_get_contents($this->tss), $this->baseDir, $template->getPrefix()))->parse()); |
|
95 | + } else { |
|
96 | + return $rules; |
|
97 | + } |
|
98 | + } else { |
|
99 | + return (new Sheet($this->tss, $this->baseDir, $template->getPrefix()))->parse(); |
|
90 | 100 | } |
91 | - else return (new Sheet($this->tss, $this->baseDir, $template->getPrefix()))->parse(); |
|
92 | 101 | } |
93 | 102 | |
94 | 103 | private function getBasicProperties($data, $locale, &$headers) { |
@@ -97,7 +106,9 @@ discard block |
||
97 | 106 | $formatter->register(new Formatter\Date($locale)); |
98 | 107 | $formatter->register(new Formatter\StringFormatter()); |
99 | 108 | |
100 | - foreach ($this->formatters as $format) $formatter->register($format); |
|
109 | + foreach ($this->formatters as $format) { |
|
110 | + $formatter->register($format); |
|
111 | + } |
|
101 | 112 | |
102 | 113 | $basicProperties = new Hook\BasicProperties($data, $headers, $formatter); |
103 | 114 | |
@@ -109,9 +120,13 @@ discard block |
||
109 | 120 | } |
110 | 121 | |
111 | 122 | private function getLocale() { |
112 | - if (is_array($this->locale)) return $this->locale; |
|
113 | - else if (strlen($this->locale) > 0) return json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'Formatter' . DIRECTORY_SEPARATOR . 'Locale' . DIRECTORY_SEPARATOR . $this->locale . '.json'), true); |
|
114 | - else return json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'Formatter' . DIRECTORY_SEPARATOR . 'Locale' . DIRECTORY_SEPARATOR . 'enGB.json'), true); |
|
123 | + if (is_array($this->locale)) { |
|
124 | + return $this->locale; |
|
125 | + } else if (strlen($this->locale) > 0) { |
|
126 | + return json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'Formatter' . DIRECTORY_SEPARATOR . 'Locale' . DIRECTORY_SEPARATOR . $this->locale . '.json'), true); |
|
127 | + } else { |
|
128 | + return json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'Formatter' . DIRECTORY_SEPARATOR . 'Locale' . DIRECTORY_SEPARATOR . 'enGB.json'), true); |
|
129 | + } |
|
115 | 130 | } |
116 | 131 | |
117 | 132 | public function registerProperties($object) { |