@@ -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 |
@@ -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 |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | |
38 | 38 | $cachedOutput = $this->loadTemplate(); |
39 | 39 | //To be a valid XML document it must have a root element, automatically wrap it in <template> to ensure it does |
40 | - $template = new Template($this->isValidDoc($cachedOutput['body']) ? $cachedOutput['body'] : '<template>' . $cachedOutput['body'] . '</template>' ); |
|
40 | + $template = new Template($this->isValidDoc($cachedOutput['body']) ? $cachedOutput['body'] : '<template>'.$cachedOutput['body'].'</template>'); |
|
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) { |
@@ -78,11 +78,11 @@ discard block |
||
78 | 78 | //N.b. only files can be cached |
79 | 79 | private function getRules($template) { |
80 | 80 | if (is_file($this->tss)) { |
81 | - $this->baseDir = dirname(realpath($this->tss)) . DIRECTORY_SEPARATOR; |
|
81 | + $this->baseDir = dirname(realpath($this->tss)).DIRECTORY_SEPARATOR; |
|
82 | 82 | //The cache for the key: the filename and template prefix |
83 | 83 | //Each template may have a different prefix which changes the parsed TSS, |
84 | 84 | //Because of this the cache needs to be generated for each template prefix. |
85 | - $key = $this->tss . $template->getPrefix() . $this->baseDir; |
|
85 | + $key = $this->tss.$template->getPrefix().$this->baseDir; |
|
86 | 86 | //Try to load the cached rules, if not set in the cache (or expired) parse the supplied sheet |
87 | 87 | $rules = $this->cache->load($key, filemtime($this->tss)); |
88 | 88 | if (!$rules) return $this->cache->write($key, (new Sheet(file_get_contents($this->tss), $this->baseDir, $template->getPrefix()))->parse()); |
@@ -107,8 +107,8 @@ discard block |
||
107 | 107 | |
108 | 108 | private function getLocale() { |
109 | 109 | if (is_array($this->locale)) return $this->locale; |
110 | - 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); |
|
111 | - else return json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'Formatter' . DIRECTORY_SEPARATOR . 'Locale' . DIRECTORY_SEPARATOR . 'enGB.json'), true); |
|
110 | + 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); |
|
111 | + else return json_decode(file_get_contents(__DIR__.DIRECTORY_SEPARATOR.'Formatter'.DIRECTORY_SEPARATOR.'Locale'.DIRECTORY_SEPARATOR.'enGB.json'), true); |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | public function registerProperties($object) { |
@@ -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) { |
@@ -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 |
@@ -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 | } |