@@ -20,7 +20,8 @@ |
||
20 | 20 | public function load($key, $modified = 0) { |
21 | 21 | if (isset($this->cache[$key]) && $this->cache[$key]['timestamp'] >= $modified) { |
22 | 22 | return $this->cache[$key]['content']; |
23 | + } else { |
|
24 | + return false; |
|
23 | 25 | } |
24 | - else return false; |
|
25 | 26 | } |
26 | 27 | } |
27 | 28 | \ No newline at end of file |
@@ -40,7 +40,9 @@ discard block |
||
40 | 40 | |
41 | 41 | //Allow $time to be set via arguments to spoof time passage during tests |
42 | 42 | foreach ($this->getRules($template) as $rule) { |
43 | - if ($rule->shouldRun($this->time)) $this->executeTssRule($rule, $template, $data); |
|
43 | + if ($rule->shouldRun($this->time)) { |
|
44 | + $this->executeTssRule($rule, $template, $data); |
|
45 | + } |
|
44 | 46 | } |
45 | 47 | |
46 | 48 | $output = $template->output($document); |
@@ -55,7 +57,9 @@ discard block |
||
55 | 57 | private function executeTssRule($rule, $template, $data) { |
56 | 58 | $rule->touch(); |
57 | 59 | $hook = new Hook\Rule($rule->properties, new Hook\PseudoMatcher($rule->pseudo, $data), $data); |
58 | - foreach ($this->registeredProperties as $properties) $hook->registerProperties($properties); |
|
60 | + foreach ($this->registeredProperties as $properties) { |
|
61 | + $hook->registerProperties($properties); |
|
62 | + } |
|
59 | 63 | $template->addHook($rule->query, $hook); |
60 | 64 | } |
61 | 65 | |
@@ -63,8 +67,9 @@ discard block |
||
63 | 67 | if (trim($this->template)[0] !== '<') { |
64 | 68 | $xml = $this->cache->load($this->template, filemtime($this->template)); |
65 | 69 | return $xml ? $xml : ['body' => file_get_contents($this->template), 'headers' => []]; |
70 | + } else { |
|
71 | + return ['body' => $this->template, 'headers' => []]; |
|
66 | 72 | } |
67 | - else return ['body' => $this->template, 'headers' => []]; |
|
68 | 73 | } |
69 | 74 | |
70 | 75 | private function getRules($template) { |
@@ -72,10 +77,14 @@ discard block |
||
72 | 77 | $this->baseDir = dirname(realpath($this->tss)) . DIRECTORY_SEPARATOR; |
73 | 78 | $key = $this->tss . $template->getPrefix() . $this->baseDir; |
74 | 79 | $rules = $this->cache->load($key, filemtime($this->tss)); |
75 | - if (!$rules) return $this->cache->write($key, (new Sheet(file_get_contents($this->tss), $this->baseDir, $template->getPrefix()))->parse()); |
|
76 | - else return $rules; |
|
80 | + if (!$rules) { |
|
81 | + return $this->cache->write($key, (new Sheet(file_get_contents($this->tss), $this->baseDir, $template->getPrefix()))->parse()); |
|
82 | + } else { |
|
83 | + return $rules; |
|
84 | + } |
|
85 | + } else { |
|
86 | + return (new Sheet($this->tss, $this->baseDir, $template->getPrefix()))->parse(); |
|
77 | 87 | } |
78 | - else return (new Sheet($this->tss, $this->baseDir, $template->getPrefix()))->parse(); |
|
79 | 88 | } |
80 | 89 | |
81 | 90 | private function getBasicProperties($data, $locale, &$headers) { |
@@ -83,7 +92,9 @@ discard block |
||
83 | 92 | $basicProperties->registerFormatter(new Formatter\Number($locale)); |
84 | 93 | $basicProperties->registerFormatter(new Formatter\Date($locale)); |
85 | 94 | $basicProperties->registerFormatter(new Formatter\StringFormatter()); |
86 | - foreach ($this->formatters as $formatter) $basicProperties->registerFormatter($formatter); |
|
95 | + foreach ($this->formatters as $formatter) { |
|
96 | + $basicProperties->registerFormatter($formatter); |
|
97 | + } |
|
87 | 98 | |
88 | 99 | return isset($this->userCache) ? new Hook\Cache($basicProperties, $this->userCache) : $basicProperties; |
89 | 100 | } |
@@ -93,9 +104,13 @@ discard block |
||
93 | 104 | } |
94 | 105 | |
95 | 106 | private function getLocale() { |
96 | - if (is_array($this->locale)) return $this->locale; |
|
97 | - 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); |
|
98 | - else return json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'Formatter' . DIRECTORY_SEPARATOR . 'Locale' . DIRECTORY_SEPARATOR . 'enGB.json'), true); |
|
107 | + if (is_array($this->locale)) { |
|
108 | + return $this->locale; |
|
109 | + } else if (strlen($this->locale) > 0) { |
|
110 | + return json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'Formatter' . DIRECTORY_SEPARATOR . 'Locale' . DIRECTORY_SEPARATOR . $this->locale . '.json'), true); |
|
111 | + } else { |
|
112 | + return json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'Formatter' . DIRECTORY_SEPARATOR . 'Locale' . DIRECTORY_SEPARATOR . 'enGB.json'), true); |
|
113 | + } |
|
99 | 114 | } |
100 | 115 | |
101 | 116 | public function registerProperties($object) { |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | |
36 | 36 | $cachedOutput = $this->loadTemplate(); |
37 | 37 | //To be a valid XML document it must have a root element, automatically wrap it in <template> to ensure it does |
38 | - $template = new Template($this->isValidDoc($cachedOutput['body']) ? $cachedOutput['body'] : '<template>' . $cachedOutput['body'] . '</template>' ); |
|
38 | + $template = new Template($this->isValidDoc($cachedOutput['body']) ? $cachedOutput['body'] : '<template>'.$cachedOutput['body'].'</template>'); |
|
39 | 39 | |
40 | 40 | //Allow $time to be set via arguments to spoof time passage during tests |
41 | 41 | foreach ($this->getRules($template) as $rule) { |
@@ -71,8 +71,8 @@ discard block |
||
71 | 71 | |
72 | 72 | private function getRules($template) { |
73 | 73 | if (is_file($this->tss)) { |
74 | - $this->baseDir = dirname(realpath($this->tss)) . DIRECTORY_SEPARATOR; |
|
75 | - $key = $this->tss . $template->getPrefix() . $this->baseDir; |
|
74 | + $this->baseDir = dirname(realpath($this->tss)).DIRECTORY_SEPARATOR; |
|
75 | + $key = $this->tss.$template->getPrefix().$this->baseDir; |
|
76 | 76 | $rules = $this->cache->load($key, filemtime($this->tss)); |
77 | 77 | if (!$rules) return $this->cache->write($key, (new Sheet(file_get_contents($this->tss), $this->baseDir, $template->getPrefix()))->parse()); |
78 | 78 | else return $rules; |
@@ -96,8 +96,8 @@ discard block |
||
96 | 96 | |
97 | 97 | private function getLocale() { |
98 | 98 | if (is_array($this->locale)) return $this->locale; |
99 | - 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); |
|
100 | - else return json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'Formatter' . DIRECTORY_SEPARATOR . 'Locale' . DIRECTORY_SEPARATOR . 'enGB.json'), true); |
|
99 | + 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); |
|
100 | + else return json_decode(file_get_contents(__DIR__.DIRECTORY_SEPARATOR.'Formatter'.DIRECTORY_SEPARATOR.'Locale'.DIRECTORY_SEPARATOR.'enGB.json'), true); |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | public function registerProperties($object) { |
@@ -10,8 +10,8 @@ discard block |
||
10 | 10 | |
11 | 11 | const S = 1; |
12 | 12 | const M = 60; |
13 | - const H = self::M*60; |
|
14 | - const D = self::H*24; |
|
13 | + const H = self::M * 60; |
|
14 | + const D = self::H * 24; |
|
15 | 15 | |
16 | 16 | |
17 | 17 | public function __construct($query, $pseudo, $depth, $index, array $properties = []) { |
@@ -39,9 +39,9 @@ discard block |
||
39 | 39 | $num = (int) $frequency; |
40 | 40 | $unit = strtoupper(trim(str_replace($num, '', $frequency))); |
41 | 41 | |
42 | - $offset = $num * constant(self::class . '::' . $unit); |
|
42 | + $offset = $num * constant(self::class.'::'.$unit); |
|
43 | 43 | |
44 | - if ($time > $this->lastRun + $offset) return true; |
|
44 | + if ($time > $this->lastRun+$offset) return true; |
|
45 | 45 | else return false; |
46 | 46 | } |
47 | 47 |
@@ -35,24 +35,33 @@ |
||
35 | 35 | } |
36 | 36 | |
37 | 37 | private function timeFrequency($frequency, $time = null) { |
38 | - if ($time === null) $time = time(); |
|
38 | + if ($time === null) { |
|
39 | + $time = time(); |
|
40 | + } |
|
39 | 41 | $num = (int) $frequency; |
40 | 42 | $unit = strtoupper(trim(str_replace($num, '', $frequency))); |
41 | 43 | |
42 | 44 | $offset = $num * constant(self::class . '::' . $unit); |
43 | 45 | |
44 | - if ($time > $this->lastRun + $offset) return true; |
|
45 | - else return false; |
|
46 | + if ($time > $this->lastRun + $offset) { |
|
47 | + return true; |
|
48 | + } else { |
|
49 | + return false; |
|
50 | + } |
|
46 | 51 | } |
47 | 52 | |
48 | 53 | public function shouldRun($time = null) { |
49 | 54 | if (isset($this->properties['update-frequency']) && $this->lastRun !== 0) { |
50 | 55 | $frequency = $this->properties['update-frequency']; |
51 | 56 | $static = ['always' => true, 'never' => false]; |
52 | - if (isset($static[$frequency])) return $static[$frequency]; |
|
53 | - else return $this->timeFrequency($frequency, $time); |
|
57 | + if (isset($static[$frequency])) { |
|
58 | + return $static[$frequency]; |
|
59 | + } else { |
|
60 | + return $this->timeFrequency($frequency, $time); |
|
61 | + } |
|
54 | 62 | |
63 | + } else { |
|
64 | + return true; |
|
55 | 65 | } |
56 | - else return true; |
|
57 | 66 | } |
58 | 67 | } |
59 | 68 | \ No newline at end of file |
@@ -9,8 +9,11 @@ |
||
9 | 9 | class PostProcess implements \Transphporm\Hook { |
10 | 10 | public function run(\DomElement $element) { |
11 | 11 | $transphporm = $element->getAttribute('transphporm'); |
12 | - if ($transphporm == 'remove') $element->parentNode->removeChild($element); |
|
13 | - else $element->removeAttribute('transphporm'); |
|
12 | + if ($transphporm == 'remove') { |
|
13 | + $element->parentNode->removeChild($element); |
|
14 | + } else { |
|
15 | + $element->removeAttribute('transphporm'); |
|
16 | + } |
|
14 | 17 | } |
15 | 18 | |
16 | 19 | } |
17 | 20 | \ No newline at end of file |