@@ -34,10 +34,14 @@ discard block |
||
| 34 | 34 | $template = new Template($this->isValidDoc($xml) ? $xml : '<template>' . $xml . '</template>' ); |
| 35 | 35 | |
| 36 | 36 | //Allow $time to be set via arguments to spoof time passage during tests |
| 37 | - if (!$time) $time = time(); |
|
| 37 | + if (!$time) { |
|
| 38 | + $time = time(); |
|
| 39 | + } |
|
| 38 | 40 | |
| 39 | 41 | foreach ($this->getRules($template) as $rule) { |
| 40 | - if ($rule->shouldRun($time)) $this->executeTssRule($rule, $template, $data); |
|
| 42 | + if ($rule->shouldRun($time)) { |
|
| 43 | + $this->executeTssRule($rule, $template, $data); |
|
| 44 | + } |
|
| 41 | 45 | } |
| 42 | 46 | |
| 43 | 47 | $output = $template->output($document); |
@@ -49,7 +53,9 @@ discard block |
||
| 49 | 53 | private function executeTssRule($rule, $template, $data) { |
| 50 | 54 | $rule->touch(); |
| 51 | 55 | $hook = new Hook\Rule($rule->properties, new Hook\PseudoMatcher($rule->pseudo, $data), $data); |
| 52 | - foreach ($this->registeredProperties as $properties) $hook->registerProperties($properties); |
|
| 56 | + foreach ($this->registeredProperties as $properties) { |
|
| 57 | + $hook->registerProperties($properties); |
|
| 58 | + } |
|
| 53 | 59 | $template->addHook($rule->query, $hook); |
| 54 | 60 | } |
| 55 | 61 | |
@@ -57,8 +63,9 @@ discard block |
||
| 57 | 63 | if (trim($this->template)[0] !== '<') { |
| 58 | 64 | $xml = $this->cache->load($this->template, filemtime($this->template)); |
| 59 | 65 | return $xml ? $xml : ['body' => file_get_contents($this->template), 'headers' => []]; |
| 66 | + } else { |
|
| 67 | + return ['body' => $this->template, 'headers' => []]; |
|
| 60 | 68 | } |
| 61 | - else return ['body' => $this->template, 'headers' => []]; |
|
| 62 | 69 | } |
| 63 | 70 | |
| 64 | 71 | private function getRules($template) { |
@@ -66,10 +73,14 @@ discard block |
||
| 66 | 73 | $this->baseDir = dirname(realpath($this->tss)) . DIRECTORY_SEPARATOR; |
| 67 | 74 | $key = $this->tss . $template->getPrefix() . $this->baseDir; |
| 68 | 75 | $rules = $this->cache->load($key, filemtime($this->tss)); |
| 69 | - if (!$rules) return $this->cache->write($key, (new Sheet(file_get_contents($this->tss), $this->baseDir, $template->getPrefix()))->parse()); |
|
| 70 | - else return $rules; |
|
| 76 | + if (!$rules) { |
|
| 77 | + return $this->cache->write($key, (new Sheet(file_get_contents($this->tss), $this->baseDir, $template->getPrefix()))->parse()); |
|
| 78 | + } else { |
|
| 79 | + return $rules; |
|
| 80 | + } |
|
| 81 | + } else { |
|
| 82 | + return (new Sheet($this->tss, $this->baseDir, $template->getPrefix()))->parse(); |
|
| 71 | 83 | } |
| 72 | - else return (new Sheet($this->tss, $this->baseDir, $template->getPrefix()))->parse(); |
|
| 73 | 84 | } |
| 74 | 85 | |
| 75 | 86 | private function getBasicProperties($data, $locale, &$headers) { |
@@ -77,7 +88,9 @@ discard block |
||
| 77 | 88 | $basicProperties->registerFormatter(new Formatter\Number($locale)); |
| 78 | 89 | $basicProperties->registerFormatter(new Formatter\Date($locale)); |
| 79 | 90 | $basicProperties->registerFormatter(new Formatter\StringFormatter()); |
| 80 | - foreach ($this->formatters as $formatter) $basicProperties->registerFormatter($formatter); |
|
| 91 | + foreach ($this->formatters as $formatter) { |
|
| 92 | + $basicProperties->registerFormatter($formatter); |
|
| 93 | + } |
|
| 81 | 94 | |
| 82 | 95 | return isset($this->userCache) ? new Hook\Cache($basicProperties, $this->userCache) : $basicProperties; |
| 83 | 96 | } |
@@ -87,9 +100,13 @@ discard block |
||
| 87 | 100 | } |
| 88 | 101 | |
| 89 | 102 | private function getLocale() { |
| 90 | - if (is_array($this->locale)) return $this->locale; |
|
| 91 | - 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); |
|
| 92 | - else return json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'Formatter' . DIRECTORY_SEPARATOR . 'Locale' . DIRECTORY_SEPARATOR . 'enGB.json'), true); |
|
| 103 | + if (is_array($this->locale)) { |
|
| 104 | + return $this->locale; |
|
| 105 | + } else if (strlen($this->locale) > 0) { |
|
| 106 | + return json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'Formatter' . DIRECTORY_SEPARATOR . 'Locale' . DIRECTORY_SEPARATOR . $this->locale . '.json'), true); |
|
| 107 | + } else { |
|
| 108 | + return json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'Formatter' . DIRECTORY_SEPARATOR . 'Locale' . DIRECTORY_SEPARATOR . 'enGB.json'), true); |
|
| 109 | + } |
|
| 93 | 110 | } |
| 94 | 111 | |
| 95 | 112 | public function registerProperties($object) { |
@@ -22,7 +22,9 @@ discard block |
||
| 22 | 22 | /** Binds data to an element */ |
| 23 | 23 | public function bind(\DomElement $element, $data) { |
| 24 | 24 | //This is a bit of a hack to workaround #24, might need a better way of doing this if it causes a problem |
| 25 | - if (is_array($data) && count($data) === 1 && isset($data[0]) && is_object($data[0])) $data = $data[0]; |
|
| 25 | + if (is_array($data) && count($data) === 1 && isset($data[0]) && is_object($data[0])) { |
|
| 26 | + $data = $data[0]; |
|
| 27 | + } |
|
| 26 | 28 | $this->dataStorage[$element] = $data; |
| 27 | 29 | } |
| 28 | 30 | |
@@ -35,7 +37,9 @@ discard block |
||
| 35 | 37 | /** Returns the data that has been bound to $element, or, if no data is bound to $element climb the DOM tree to find the data bound to a parent node*/ |
| 36 | 38 | private function getData(\DomElement $element) { |
| 37 | 39 | while ($element) { |
| 38 | - if (isset($this->dataStorage[$element])) return $this->dataStorage[$element]; |
|
| 40 | + if (isset($this->dataStorage[$element])) { |
|
| 41 | + return $this->dataStorage[$element]; |
|
| 42 | + } |
|
| 39 | 43 | $element = $element->parentNode; |
| 40 | 44 | } |
| 41 | 45 | return $this->data; |
@@ -52,16 +56,24 @@ discard block |
||
| 52 | 56 | $parts = explode('.', $name[0]); |
| 53 | 57 | $obj = $data; |
| 54 | 58 | foreach ($parts as $part) { |
| 55 | - if ($part === '') continue; |
|
| 56 | - if (is_callable([$obj, $part])) $obj = call_user_func([$obj, $part]); |
|
| 57 | - else $obj = $this->ifNull($obj, $part); |
|
| 59 | + if ($part === '') { |
|
| 60 | + continue; |
|
| 61 | + } |
|
| 62 | + if (is_callable([$obj, $part])) { |
|
| 63 | + $obj = call_user_func([$obj, $part]); |
|
| 64 | + } else { |
|
| 65 | + $obj = $this->ifNull($obj, $part); |
|
| 66 | + } |
|
| 58 | 67 | } |
| 59 | 68 | return $obj; |
| 60 | 69 | } |
| 61 | 70 | |
| 62 | 71 | private function ifNull($obj, $key) { |
| 63 | - if (is_array($obj)) return isset($obj[$key]) ? $obj[$key] : null; |
|
| 64 | - else return isset($obj->$key) ? $obj->$key : null; |
|
| 72 | + if (is_array($obj)) { |
|
| 73 | + return isset($obj[$key]) ? $obj[$key] : null; |
|
| 74 | + } else { |
|
| 75 | + return isset($obj->$key) ? $obj->$key : null; |
|
| 76 | + } |
|
| 65 | 77 | } |
| 66 | 78 | |
| 67 | 79 | public function attr($val, $element) { |
@@ -87,14 +99,18 @@ discard block |
||
| 87 | 99 | |
| 88 | 100 | $doc = $newTemplate->output([], true)->body; |
| 89 | 101 | |
| 90 | - if (isset($val[1])) return $this->templateSubsection($val[1], $doc, $element); |
|
| 102 | + if (isset($val[1])) { |
|
| 103 | + return $this->templateSubsection($val[1], $doc, $element); |
|
| 104 | + } |
|
| 91 | 105 | |
| 92 | 106 | $newNode = $element->ownerDocument->importNode($doc->documentElement, true); |
| 93 | 107 | |
| 94 | 108 | $result = []; |
| 95 | 109 | |
| 96 | 110 | if ($newNode->tagName === 'template') { |
| 97 | - foreach ($newNode->childNodes as $node) $result[] = $node->cloneNode(true); |
|
| 111 | + foreach ($newNode->childNodes as $node) { |
|
| 112 | + $result[] = $node->cloneNode(true); |
|
| 113 | + } |
|
| 98 | 114 | } |
| 99 | 115 | //else $result[] = $newNode; |
| 100 | 116 | |
@@ -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 = []) { |
@@ -43,9 +43,9 @@ discard block |
||
| 43 | 43 | $num = (int) $frequency; |
| 44 | 44 | $unit = strtoupper(trim(str_replace($num, '', $frequency))); |
| 45 | 45 | |
| 46 | - $offset = $num * constant(self::class . '::' . $unit); |
|
| 46 | + $offset = $num * constant(self::class.'::'.$unit); |
|
| 47 | 47 | |
| 48 | - if ($time > $this->lastRun + $offset) return true; |
|
| 48 | + if ($time > $this->lastRun+$offset) return true; |
|
| 49 | 49 | else return false; |
| 50 | 50 | |
| 51 | 51 | } |
@@ -38,17 +38,23 @@ |
||
| 38 | 38 | if (isset($this->properties['update-frequency']) && $this->lastRun !== 0) { |
| 39 | 39 | $frequency = $this->properties['update-frequency']; |
| 40 | 40 | $static = ['always' => true, 'never' => false]; |
| 41 | - if (isset($static[$frequency])) return $static[$frequency]; |
|
| 41 | + if (isset($static[$frequency])) { |
|
| 42 | + return $static[$frequency]; |
|
| 43 | + } |
|
| 42 | 44 | |
| 43 | 45 | $num = (int) $frequency; |
| 44 | 46 | $unit = strtoupper(trim(str_replace($num, '', $frequency))); |
| 45 | 47 | |
| 46 | 48 | $offset = $num * constant(self::class . '::' . $unit); |
| 47 | 49 | |
| 48 | - if ($time > $this->lastRun + $offset) return true; |
|
| 49 | - else return false; |
|
| 50 | + if ($time > $this->lastRun + $offset) { |
|
| 51 | + return true; |
|
| 52 | + } else { |
|
| 53 | + return false; |
|
| 54 | + } |
|
| 50 | 55 | |
| 56 | + } else { |
|
| 57 | + return true; |
|
| 51 | 58 | } |
| 52 | - else return true; |
|
| 53 | 59 | } |
| 54 | 60 | } |
| 55 | 61 | \ No newline at end of file |
@@ -31,7 +31,9 @@ discard block |
||
| 31 | 31 | $rules = $this->writeRule($rules, $selector, $rule); |
| 32 | 32 | } |
| 33 | 33 | //there may be processing instructions at the end |
| 34 | - if ($processing = $this->processingInstructions($this->tss, $pos, strlen($this->tss))) $rules = array_merge($processing['rules'], $rules); |
|
| 34 | + if ($processing = $this->processingInstructions($this->tss, $pos, strlen($this->tss))) { |
|
| 35 | + $rules = array_merge($processing['rules'], $rules); |
|
| 36 | + } |
|
| 35 | 37 | usort($rules, [$this, 'sortRules']); |
| 36 | 38 | return $rules; |
| 37 | 39 | } |
@@ -43,7 +45,9 @@ discard block |
||
| 43 | 45 | } |
| 44 | 46 | |
| 45 | 47 | private function writeRule($rules, $selector, $newRule) { |
| 46 | - if (isset($rules[$selector])) $newRule->properties = array_merge($rules[$selector], $newRule->properties); |
|
| 48 | + if (isset($rules[$selector])) { |
|
| 49 | + $newRule->properties = array_merge($rules[$selector], $newRule->properties); |
|
| 50 | + } |
|
| 47 | 51 | $rules[$selector] = $newRule; |
| 48 | 52 | |
| 49 | 53 | return $rules; |
@@ -58,8 +62,7 @@ discard block |
||
| 58 | 62 | $pos = strpos($tss, ';', $spacePos); |
| 59 | 63 | $args = substr($tss, $spacePos+1, $pos-$spacePos-1); |
| 60 | 64 | $rules = array_merge($rules, $this->$funcName($args)); |
| 61 | - } |
|
| 62 | - else { |
|
| 65 | + } else { |
|
| 63 | 66 | break; |
| 64 | 67 | } |
| 65 | 68 | } |
@@ -74,7 +77,9 @@ discard block |
||
| 74 | 77 | |
| 75 | 78 | private function sortRules($a, $b) { |
| 76 | 79 | //If they have the same depth, compare on index |
| 77 | - if ($a->depth === $b->depth) return $a->index < $b->index ? -1 : 1; |
|
| 80 | + if ($a->depth === $b->depth) { |
|
| 81 | + return $a->index < $b->index ? -1 : 1; |
|
| 82 | + } |
|
| 78 | 83 | |
| 79 | 84 | return ($a->depth < $b->depth) ? -1 : 1; |
| 80 | 85 | } |
@@ -95,7 +100,9 @@ discard block |
||
| 95 | 100 | $return = []; |
| 96 | 101 | |
| 97 | 102 | foreach ($rules as $rule) { |
| 98 | - if (trim($rule) === '') continue; |
|
| 103 | + if (trim($rule) === '') { |
|
| 104 | + continue; |
|
| 105 | + } |
|
| 99 | 106 | $parts = explode(':', $rule, 2); |
| 100 | 107 | |
| 101 | 108 | $parts[1] = $stringExtractor->rebuild($parts[1]); |