@@ -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) { |
@@ -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 |
@@ -63,12 +63,15 @@ discard block |
||
| 63 | 63 | $node = $element->ownerDocument->importNode($node, true); |
| 64 | 64 | $element->appendChild($node); |
| 65 | 65 | } |
| 66 | + } else { |
|
| 67 | + $element->appendChild($element->ownerDocument->createTextNode(implode('', $content))); |
|
| 66 | 68 | } |
| 67 | - else $element->appendChild($element->ownerDocument->createTextNode(implode('', $content))); |
|
| 68 | 69 | } |
| 69 | 70 | |
| 70 | 71 | private function removeAllChildren($element) { |
| 71 | - while ($element->hasChildNodes()) $element->removeChild($element->firstChild); |
|
| 72 | + while ($element->hasChildNodes()) { |
|
| 73 | + $element->removeChild($element->firstChild); |
|
| 74 | + } |
|
| 72 | 75 | } |
| 73 | 76 | |
| 74 | 77 | public function registerFormatter($formatter) { |
@@ -76,11 +79,15 @@ discard block |
||
| 76 | 79 | } |
| 77 | 80 | |
| 78 | 81 | private function format($value, $rules) { |
| 79 | - if (!isset($rules['format'])) return $value; |
|
| 82 | + if (!isset($rules['format'])) { |
|
| 83 | + return $value; |
|
| 84 | + } |
|
| 80 | 85 | $format = new \Transphporm\StringExtractor($rules['format']); |
| 81 | 86 | $options = explode(' ', $format); |
| 82 | 87 | $functionName = array_shift($options); |
| 83 | - foreach ($options as &$f) $f = trim($format->rebuild($f), '"'); |
|
| 88 | + foreach ($options as &$f) { |
|
| 89 | + $f = trim($format->rebuild($f), '"'); |
|
| 90 | + } |
|
| 84 | 91 | |
| 85 | 92 | return $this->processFormat($options, $functionName, $value); |
| 86 | 93 | } |
@@ -109,7 +116,9 @@ discard block |
||
| 109 | 116 | unset($newRules['repeat']); |
| 110 | 117 | |
| 111 | 118 | $hook = new Rule($newRules, $rule->getPseudoMatcher(), $this->data); |
| 112 | - foreach ($rule->getProperties() as $obj) $hook->registerProperties($obj); |
|
| 119 | + foreach ($rule->getProperties() as $obj) { |
|
| 120 | + $hook->registerProperties($obj); |
|
| 121 | + } |
|
| 113 | 122 | $hook->run($clone); |
| 114 | 123 | } |
| 115 | 124 | |
@@ -120,7 +129,9 @@ discard block |
||
| 120 | 129 | } |
| 121 | 130 | |
| 122 | 131 | public function display($value, $element) { |
| 123 | - if (strtolower($value[0]) === 'none') $element->setAttribute('transphporm', 'remove'); |
|
| 132 | + if (strtolower($value[0]) === 'none') { |
|
| 133 | + $element->setAttribute('transphporm', 'remove'); |
|
| 134 | + } |
|
| 124 | 135 | } |
| 125 | 136 | |
| 126 | 137 | public function bind($value, $element) { |
@@ -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 |
@@ -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) && $this->isObjectArray($data)) $data = $data[0]; |
|
| 25 | + if (is_array($data) && $this->isObjectArray($data)) { |
|
| 26 | + $data = $data[0]; |
|
| 27 | + } |
|
| 26 | 28 | $this->dataStorage[$element] = $data; |
| 27 | 29 | } |
| 28 | 30 | |
@@ -38,7 +40,9 @@ discard block |
||
| 38 | 40 | /** 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*/ |
| 39 | 41 | private function getData(\DomElement $element) { |
| 40 | 42 | while ($element) { |
| 41 | - if (isset($this->dataStorage[$element])) return $this->dataStorage[$element]; |
|
| 43 | + if (isset($this->dataStorage[$element])) { |
|
| 44 | + return $this->dataStorage[$element]; |
|
| 45 | + } |
|
| 42 | 46 | $element = $element->parentNode; |
| 43 | 47 | } |
| 44 | 48 | return $this->data; |
@@ -55,16 +59,24 @@ discard block |
||
| 55 | 59 | $parts = explode('.', $name[0]); |
| 56 | 60 | $obj = $data; |
| 57 | 61 | foreach ($parts as $part) { |
| 58 | - if ($part === '') continue; |
|
| 59 | - if (is_callable([$obj, $part])) $obj = call_user_func([$obj, $part]); |
|
| 60 | - else $obj = $this->ifNull($obj, $part); |
|
| 62 | + if ($part === '') { |
|
| 63 | + continue; |
|
| 64 | + } |
|
| 65 | + if (is_callable([$obj, $part])) { |
|
| 66 | + $obj = call_user_func([$obj, $part]); |
|
| 67 | + } else { |
|
| 68 | + $obj = $this->ifNull($obj, $part); |
|
| 69 | + } |
|
| 61 | 70 | } |
| 62 | 71 | return $obj; |
| 63 | 72 | } |
| 64 | 73 | |
| 65 | 74 | private function ifNull($obj, $key) { |
| 66 | - if (is_array($obj)) return isset($obj[$key]) ? $obj[$key] : null; |
|
| 67 | - else return isset($obj->$key) ? $obj->$key : null; |
|
| 75 | + if (is_array($obj)) { |
|
| 76 | + return isset($obj[$key]) ? $obj[$key] : null; |
|
| 77 | + } else { |
|
| 78 | + return isset($obj->$key) ? $obj->$key : null; |
|
| 79 | + } |
|
| 68 | 80 | } |
| 69 | 81 | |
| 70 | 82 | public function attr($val, $element) { |
@@ -90,14 +102,18 @@ discard block |
||
| 90 | 102 | |
| 91 | 103 | $doc = $newTemplate->output([], true)->body; |
| 92 | 104 | |
| 93 | - if (isset($val[1])) return $this->templateSubsection($val[1], $doc, $element); |
|
| 105 | + if (isset($val[1])) { |
|
| 106 | + return $this->templateSubsection($val[1], $doc, $element); |
|
| 107 | + } |
|
| 94 | 108 | |
| 95 | 109 | $newNode = $element->ownerDocument->importNode($doc->documentElement, true); |
| 96 | 110 | |
| 97 | 111 | $result = []; |
| 98 | 112 | |
| 99 | 113 | if ($newNode->tagName === 'template') { |
| 100 | - foreach ($newNode->childNodes as $node) $result[] = $node->cloneNode(true); |
|
| 114 | + foreach ($newNode->childNodes as $node) { |
|
| 115 | + $result[] = $node->cloneNode(true); |
|
| 116 | + } |
|
| 101 | 117 | } |
| 102 | 118 | //else $result[] = $newNode; |
| 103 | 119 | |