@@ -37,8 +37,9 @@ discard block |
||
37 | 37 | $selector = $this->createSelector(); |
38 | 38 | $selector->type = $css[$i]; |
39 | 39 | $selectors[] = $selector; |
40 | + } else { |
|
41 | + $selector->string .= $css[$i]; |
|
40 | 42 | } |
41 | - else $selector->string .= $css[$i]; |
|
42 | 43 | } |
43 | 44 | return $selectors; |
44 | 45 | } |
@@ -49,7 +50,9 @@ discard block |
||
49 | 50 | $this->depth = count($selectors); |
50 | 51 | $xpath = '/'; |
51 | 52 | foreach ($selectors as $selector) { |
52 | - if (isset($this->translators[$selector->type])) $xpath .= $this->translators[$selector->type]($selector->string); |
|
53 | + if (isset($this->translators[$selector->type])) { |
|
54 | + $xpath .= $this->translators[$selector->type]($selector->string); |
|
55 | + } |
|
53 | 56 | } |
54 | 57 | |
55 | 58 | $xpath = str_replace('/[', '/*[', $xpath); |
@@ -44,8 +44,11 @@ discard block |
||
44 | 44 | |
45 | 45 | $diffDays = $diff->invert === 1 ? $diff->days : 0- $diff->days; |
46 | 46 | |
47 | - if ($diffDays !== 0) return $this->dayOffset($diffDays); |
|
48 | - else return $this->timeOffset($diff); |
|
47 | + if ($diffDays !== 0) { |
|
48 | + return $this->dayOffset($diffDays); |
|
49 | + } else { |
|
50 | + return $this->timeOffset($diff); |
|
51 | + } |
|
49 | 52 | } |
50 | 53 | |
51 | 54 | /** Calculates offset in hours/minutes/seconds */ |
@@ -80,15 +83,22 @@ discard block |
||
80 | 83 | [-365, -28, $strings['future'], 28, 'months'], |
81 | 84 | [-999999, -365, $strings['future'], 365, 'years'], |
82 | 85 | ]; |
83 | - if (isset($strings['day_before_yesterday'])) array_unshift($ranges, [2, 2, $strings['day_before_yesterday'], 1, '']); |
|
84 | - if (isset($strings['day_after_tomorrow'])) array_unshift($ranges, [-2, -2, $strings['day_after_tomorrow'], 1, '']); |
|
86 | + if (isset($strings['day_before_yesterday'])) { |
|
87 | + array_unshift($ranges, [2, 2, $strings['day_before_yesterday'], 1, '']); |
|
88 | + } |
|
89 | + if (isset($strings['day_after_tomorrow'])) { |
|
90 | + array_unshift($ranges, [-2, -2, $strings['day_after_tomorrow'], 1, '']); |
|
91 | + } |
|
85 | 92 | return $ranges; |
86 | 93 | } |
87 | 94 | |
88 | 95 | /** Converts "week" to "weeks", "month" to "months" etc when plural is required using language from $locale */ |
89 | 96 | private function getPlural($strings, $num, $interval) { |
90 | - if ($interval !== '') return $num == 1 ? $strings[$interval . '_singular'] : $strings[$interval . '_plural']; |
|
91 | - else return ''; |
|
97 | + if ($interval !== '') { |
|
98 | + return $num == 1 ? $strings[$interval . '_singular'] : $strings[$interval . '_plural']; |
|
99 | + } else { |
|
100 | + return ''; |
|
101 | + } |
|
92 | 102 | } |
93 | 103 | |
94 | 104 | /** Calculates offset in days/weeks/month/years */ |
@@ -13,7 +13,10 @@ |
||
13 | 13 | |
14 | 14 | public function currency($num) { |
15 | 15 | $num = $this->decimal($num, $this->locale['currency_decimals']); |
16 | - if ($this->locale['currency_position'] === 'before') return $this->locale['currency'] . $num; |
|
17 | - else return $num . $this->locale['currency']; |
|
16 | + if ($this->locale['currency_position'] === 'before') { |
|
17 | + return $this->locale['currency'] . $num; |
|
18 | + } else { |
|
19 | + return $num . $this->locale['currency']; |
|
20 | + } |
|
18 | 21 | } |
19 | 22 | } |
20 | 23 | \ No newline at end of file |
@@ -58,12 +58,15 @@ discard block |
||
58 | 58 | $node = $element->ownerDocument->importNode($node, true); |
59 | 59 | $element->appendChild($node); |
60 | 60 | } |
61 | + } else { |
|
62 | + $element->appendChild($element->ownerDocument->createTextNode(implode('', $content))); |
|
61 | 63 | } |
62 | - else $element->appendChild($element->ownerDocument->createTextNode(implode('', $content))); |
|
63 | 64 | } |
64 | 65 | |
65 | 66 | private function removeAllChildren($element) { |
66 | - while ($element->hasChildNodes()) $element->removeChild($element->firstChild); |
|
67 | + while ($element->hasChildNodes()) { |
|
68 | + $element->removeChild($element->firstChild); |
|
69 | + } |
|
67 | 70 | } |
68 | 71 | |
69 | 72 | public function registerFormatter($formatter) { |
@@ -71,11 +74,15 @@ discard block |
||
71 | 74 | } |
72 | 75 | |
73 | 76 | private function format($value, $rules) { |
74 | - if (!isset($rules['format'])) return $value; |
|
77 | + if (!isset($rules['format'])) { |
|
78 | + return $value; |
|
79 | + } |
|
75 | 80 | $format = new \Transphporm\StringExtractor($rules['format']); |
76 | 81 | $options = explode(' ', $format); |
77 | 82 | $functionName = array_shift($options); |
78 | - foreach ($options as &$f) $f = trim($format->rebuild($f), '"'); |
|
83 | + foreach ($options as &$f) { |
|
84 | + $f = trim($format->rebuild($f), '"'); |
|
85 | + } |
|
79 | 86 | |
80 | 87 | return $this->processFormat($options, $functionName, $value); |
81 | 88 | } |
@@ -104,7 +111,9 @@ discard block |
||
104 | 111 | unset($newRules['repeat']); |
105 | 112 | |
106 | 113 | $hook = new Rule($newRules, $rule->getPseudoMatcher(), $this->data); |
107 | - foreach ($rule->getProperties() as $obj) $hook->registerProperties($obj); |
|
114 | + foreach ($rule->getProperties() as $obj) { |
|
115 | + $hook->registerProperties($obj); |
|
116 | + } |
|
108 | 117 | $hook->run($clone); |
109 | 118 | } |
110 | 119 | |
@@ -115,7 +124,9 @@ discard block |
||
115 | 124 | } |
116 | 125 | |
117 | 126 | public function display($value, $element) { |
118 | - if (strtolower($value[0]) === 'none') $element->parentNode->removeChild($element); |
|
127 | + if (strtolower($value[0]) === 'none') { |
|
128 | + $element->parentNode->removeChild($element); |
|
129 | + } |
|
119 | 130 | } |
120 | 131 | |
121 | 132 | public function bind($value, $element) { |
@@ -22,12 +22,16 @@ discard block |
||
22 | 22 | |
23 | 23 | private function attribute($pseudo, $element) { |
24 | 24 | $pos = strpos($pseudo, '['); |
25 | - if ($pos === false) return true; |
|
25 | + if ($pos === false) { |
|
26 | + return true; |
|
27 | + } |
|
26 | 28 | $end = strpos($pseudo, ']', $pos); |
27 | 29 | |
28 | 30 | $name = substr($pseudo, 0, $pos); |
29 | 31 | |
30 | - if (strpos($pseudo, '=') === false) return true; |
|
32 | + if (strpos($pseudo, '=') === false) { |
|
33 | + return true; |
|
34 | + } |
|
31 | 35 | |
32 | 36 | $criteria = substr($pseudo, $pos+1, $end-$pos-1); |
33 | 37 | list ($field, $value) = explode('=', $criteria); |
@@ -42,16 +46,21 @@ discard block |
||
42 | 46 | } |
43 | 47 | |
44 | 48 | private function parseValue($value) { |
45 | - if ($value == 'true') return true; |
|
46 | - else if ($value == 'false') return false; |
|
47 | - else return $value; |
|
49 | + if ($value == 'true') { |
|
50 | + return true; |
|
51 | + } else if ($value == 'false') { |
|
52 | + return false; |
|
53 | + } else { |
|
54 | + return $value; |
|
55 | + } |
|
48 | 56 | } |
49 | 57 | |
50 | 58 | private function getOperator($field) { |
51 | 59 | if ($field[strlen($field)-1] == '!') { |
52 | 60 | return '!'; |
61 | + } else { |
|
62 | + return ''; |
|
53 | 63 | } |
54 | - else return ''; |
|
55 | 64 | } |
56 | 65 | |
57 | 66 | private function nth($pseudo, $element) { |
@@ -59,8 +68,11 @@ discard block |
||
59 | 68 | $criteria = $this->getBetween($pseudo, '(', ')'); |
60 | 69 | $num = $this->getBetween($element->getNodePath(), '[', ']'); |
61 | 70 | |
62 | - if (is_callable([$this, $criteria])) return $this->$criteria($num); |
|
63 | - else return $num == $criteria; |
|
71 | + if (is_callable([$this, $criteria])) { |
|
72 | + return $this->$criteria($num); |
|
73 | + } else { |
|
74 | + return $num == $criteria; |
|
75 | + } |
|
64 | 76 | |
65 | 77 | } |
66 | 78 | return true; |
@@ -80,7 +92,9 @@ discard block |
||
80 | 92 | public function header($element) { |
81 | 93 | if ($this->matches($element)) { |
82 | 94 | foreach ($this->pseudo as $pseudo) { |
83 | - if (strpos($pseudo, 'header') === 0) return $this->getBetween($pseudo, '[', ']'); |
|
95 | + if (strpos($pseudo, 'header') === 0) { |
|
96 | + return $this->getBetween($pseudo, '[', ']'); |
|
97 | + } |
|
84 | 98 | } |
85 | 99 | } |
86 | 100 | } |
@@ -95,7 +109,9 @@ discard block |
||
95 | 109 | |
96 | 110 | private function getBetween($string, $start, $end) { |
97 | 111 | $open = strpos($string, $start); |
98 | - if ($open === false) return false; |
|
112 | + if ($open === false) { |
|
113 | + return false; |
|
114 | + } |
|
99 | 115 | $close = strpos($string, $end, $open); |
100 | 116 | return substr($string, $open+1, $close-$open-1); |
101 | 117 | } |
@@ -15,11 +15,15 @@ discard block |
||
15 | 15 | |
16 | 16 | public function run(\DomElement $element) { |
17 | 17 | //Don't run if there's a pseudo element like nth-child() and this element doesn't match it |
18 | - if (!$this->pseudoMatcher->matches($element)) return; |
|
18 | + if (!$this->pseudoMatcher->matches($element)) { |
|
19 | + return; |
|
20 | + } |
|
19 | 21 | |
20 | 22 | foreach ($this->rules as $name => $value) { |
21 | 23 | $result = $this->callProperty($name, $element, $this->parseValue(trim($value), $element)); |
22 | - if ($result === false) break; |
|
24 | + if ($result === false) { |
|
25 | + break; |
|
26 | + } |
|
23 | 27 | } |
24 | 28 | } |
25 | 29 | |
@@ -52,8 +56,9 @@ discard block |
||
52 | 56 | $pos = $start+1; |
53 | 57 | $end = 0; |
54 | 58 | while ($end = strpos($string, $char, $pos)) { |
55 | - if ($string[$end-1] === $escape) $pos = $end+1; |
|
56 | - else { |
|
59 | + if ($string[$end-1] === $escape) { |
|
60 | + $pos = $end+1; |
|
61 | + } else { |
|
57 | 62 | break; |
58 | 63 | } |
59 | 64 | } |
@@ -74,14 +79,17 @@ discard block |
||
74 | 79 | |
75 | 80 | //Count the number of fresh opening ( before $close |
76 | 81 | $cPos = $open+1; |
77 | - while (($cPos = strpos($function, '(', $cPos+1)) !== false && $cPos < $close) $close = strpos($function, ')', $close+1); |
|
82 | + while (($cPos = strpos($function, '(', $cPos+1)) !== false && $cPos < $close) { |
|
83 | + $close = strpos($function, ')', $close+1); |
|
84 | + } |
|
78 | 85 | |
79 | 86 | $name = substr($function, 0, $open); |
80 | 87 | |
81 | 88 | $params = substr($function, $open+1, $close-$open-1); |
82 | 89 | return ['name' => $name, 'params' => $params, 'endPoint' => $close]; |
90 | + } else { |
|
91 | + return ['name' => null, 'params' => $function, 'endPoint' => strlen($function)]; |
|
83 | 92 | } |
84 | - else return ['name' => null, 'params' => $function, 'endPoint' => strlen($function)]; |
|
85 | 93 | |
86 | 94 | } |
87 | 95 | |
@@ -90,23 +98,26 @@ discard block |
||
90 | 98 | if ($function && in_array($function[0], ['\'', '"'])) { |
91 | 99 | $finalPos = $this->findMatchingPos($function, $function[0]); |
92 | 100 | $result[] = $this->extractQuotedString($function[0], $function); |
93 | - } |
|
94 | - else { |
|
101 | + } else { |
|
95 | 102 | $func = $this->parseFunction($function); |
96 | 103 | $finalPos = $func['endPoint']; |
97 | 104 | |
98 | 105 | if (($data = $this->callFunc($func['name'], $func['params'], $element)) !== false) { |
99 | 106 | $result = $this->appendToArray($result, $data); |
100 | - } |
|
101 | - else $result[] = trim($function); |
|
107 | + } else { |
|
108 | + $result[] = trim($function); |
|
109 | + } |
|
102 | 110 | } |
103 | 111 | $remaining = trim(substr($function, $finalPos+1)); |
104 | 112 | return $this->parseNextValue($remaining, $result, $element); |
105 | 113 | } |
106 | 114 | |
107 | 115 | private function appendToArray($array, $value) { |
108 | - if (is_array($value)) $array += $value; |
|
109 | - else $array[] = $value; |
|
116 | + if (is_array($value)) { |
|
117 | + $array += $value; |
|
118 | + } else { |
|
119 | + $array[] = $value; |
|
120 | + } |
|
110 | 121 | return $array; |
111 | 122 | } |
112 | 123 | |
@@ -118,7 +129,9 @@ discard block |
||
118 | 129 | } |
119 | 130 | |
120 | 131 | private function parseNextValue($remaining, $result, $element) { |
121 | - if (strlen($remaining) > 0 && $remaining[0] == ',') $result = array_merge($result, $this->parseValue(trim(substr($remaining, 1)), $element)); |
|
132 | + if (strlen($remaining) > 0 && $remaining[0] == ',') { |
|
133 | + $result = array_merge($result, $this->parseValue(trim(substr($remaining, 1)), $element)); |
|
134 | + } |
|
122 | 135 | return $result; |
123 | 136 | } |
124 | 137 |
@@ -16,7 +16,9 @@ |
||
16 | 16 | $strings = []; |
17 | 17 | while (($pos = strpos($str, '"', $pos+1)) !== false) { |
18 | 18 | $end = strpos($str, '"', $pos+1); |
19 | - while ($str[$end-1] == '\\') $end = strpos($str, '"', $end+1); |
|
19 | + while ($str[$end-1] == '\\') { |
|
20 | + $end = strpos($str, '"', $end+1); |
|
21 | + } |
|
20 | 22 | $strings['$+STR' . ++$num] = substr($str, $pos, $end-$pos+1); |
21 | 23 | $str = substr_replace($str, '$+STR' . $num, $pos, $end-$pos+1); |
22 | 24 | } |
@@ -33,14 +33,18 @@ discard block |
||
33 | 33 | /** Loops through all assigned hooks, runs the Xpath query and calls the hook */ |
34 | 34 | private function processHooks() { |
35 | 35 | foreach ($this->hooks as list($query, $hook)) { |
36 | - foreach ($this->xpath->query($query) as $element) $hook->run($element); |
|
36 | + foreach ($this->xpath->query($query) as $element) { |
|
37 | + $hook->run($element); |
|
38 | + } |
|
37 | 39 | } |
38 | 40 | } |
39 | 41 | |
40 | 42 | /** Prints out the current DomDocument as HTML */ |
41 | 43 | private function printDocument(\DomDocument $doc) { |
42 | 44 | $output = ''; |
43 | - foreach ($doc->documentElement->childNodes as $node) $output .= $doc->saveXML($node, LIBXML_NOEMPTYTAG); |
|
45 | + foreach ($doc->documentElement->childNodes as $node) { |
|
46 | + $output .= $doc->saveXML($node, LIBXML_NOEMPTYTAG); |
|
47 | + } |
|
44 | 48 | return $output; |
45 | 49 | } |
46 | 50 | |
@@ -52,13 +56,18 @@ discard block |
||
52 | 56 | //Generate the document by taking only the childnodes of the template, ignoring the <template> and </template> tags |
53 | 57 | //TODO: Is there a faster way of doing this without string manipulation on the output or this loop through childnodes? |
54 | 58 | //Either return a whole DomDocument or return the output HTML |
55 | - if ($document) return $this->document; |
|
59 | + if ($document) { |
|
60 | + return $this->document; |
|
61 | + } |
|
56 | 62 | |
57 | 63 | |
58 | 64 | $output = ($this->document->doctype) ? $this->document->saveXml($this->document->doctype) . "\n" : ''; |
59 | 65 | |
60 | - if ($this->document->documentElement->tagName !== 'template') $output .= $this->document->saveXml($this->document->documentElement, LIBXML_NOEMPTYTAG); |
|
61 | - else $output = $this->printDocument($this->document); |
|
66 | + if ($this->document->documentElement->tagName !== 'template') { |
|
67 | + $output .= $this->document->saveXml($this->document->documentElement, LIBXML_NOEMPTYTAG); |
|
68 | + } else { |
|
69 | + $output = $this->printDocument($this->document); |
|
70 | + } |
|
62 | 71 | |
63 | 72 | //repair empty tags. Browsers break on <script /> and <div /> so can't avoid LIBXML_NOEMPTYTAG but they also break on <base></base> so repair them |
64 | 73 | $output = str_replace(['></img>', '></br>', '></meta>', '></base>', '></link>', '></hr>', '></input>'], ' />', $output); |
@@ -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) { |