@@ -63,6 +63,9 @@ discard block |
||
63 | 63 | return $array; |
64 | 64 | } |
65 | 65 | |
66 | + /** |
|
67 | + * @param null|\DOMElement $element |
|
68 | + */ |
|
66 | 69 | private function callFunc($name, $params, $element) { |
67 | 70 | if ($name && is_callable([$this->dataFunction, $name])) { |
68 | 71 | return $this->dataFunction->$name($this->parse($params, $element), $element); |
@@ -70,6 +73,10 @@ discard block |
||
70 | 73 | return false; |
71 | 74 | } |
72 | 75 | |
76 | + /** |
|
77 | + * @param string $remaining |
|
78 | + * @param null|\DOMElement $element |
|
79 | + */ |
|
73 | 80 | private function parseNextValue($remaining, $result, $element) { |
74 | 81 | if (strlen($remaining) > 0 && $remaining[0] == ',') $result = array_merge($result, $this->parse(trim(substr($remaining, 1)), $element)); |
75 | 82 | return $result; |
@@ -27,14 +27,17 @@ discard block |
||
27 | 27 | |
28 | 28 | //Count the number of fresh opening ( before $close |
29 | 29 | $cPos = $open+1; |
30 | - while (($cPos = strpos($function, '(', $cPos+1)) !== false && $cPos < $close) $close = strpos($function, ')', $close+1); |
|
30 | + while (($cPos = strpos($function, '(', $cPos+1)) !== false && $cPos < $close) { |
|
31 | + $close = strpos($function, ')', $close+1); |
|
32 | + } |
|
31 | 33 | |
32 | 34 | $name = substr($function, 0, $open); |
33 | 35 | |
34 | 36 | $params = substr($function, $open+1, $close-$open-1); |
35 | 37 | return ['name' => $name, 'params' => $params, 'endPoint' => $close]; |
38 | + } else { |
|
39 | + return ['name' => null, 'params' => $function, 'endPoint' => strlen($function)]; |
|
36 | 40 | } |
37 | - else return ['name' => null, 'params' => $function, 'endPoint' => strlen($function)]; |
|
38 | 41 | |
39 | 42 | } |
40 | 43 | |
@@ -43,23 +46,26 @@ discard block |
||
43 | 46 | if ($function && in_array($function[0], ['\'', '"'])) { |
44 | 47 | $finalPos = $this->findMatchingPos($function, $function[0]); |
45 | 48 | $result[] = $this->extractQuotedString($function[0], $function); |
46 | - } |
|
47 | - else { |
|
49 | + } else { |
|
48 | 50 | $func = $this->parseFunction($function); |
49 | 51 | $finalPos = $func['endPoint']; |
50 | 52 | |
51 | 53 | if (($data = $this->callFunc($func['name'], $func['params'], $element)) !== false) { |
52 | 54 | $result = $this->appendToArray($result, $data); |
53 | - } |
|
54 | - else $result[] = trim($function); |
|
55 | + } else { |
|
56 | + $result[] = trim($function); |
|
57 | + } |
|
55 | 58 | } |
56 | 59 | $remaining = trim(substr($function, $finalPos+1)); |
57 | 60 | return $this->parseNextValue($remaining, $result, $element); |
58 | 61 | } |
59 | 62 | |
60 | 63 | private function appendToArray($array, $value) { |
61 | - if (is_array($value)) $array += $value; |
|
62 | - else $array[] = $value; |
|
64 | + if (is_array($value)) { |
|
65 | + $array += $value; |
|
66 | + } else { |
|
67 | + $array[] = $value; |
|
68 | + } |
|
63 | 69 | return $array; |
64 | 70 | } |
65 | 71 | |
@@ -71,7 +77,9 @@ discard block |
||
71 | 77 | } |
72 | 78 | |
73 | 79 | private function parseNextValue($remaining, $result, $element) { |
74 | - if (strlen($remaining) > 0 && $remaining[0] == ',') $result = array_merge($result, $this->parse(trim(substr($remaining, 1)), $element)); |
|
80 | + if (strlen($remaining) > 0 && $remaining[0] == ',') { |
|
81 | + $result = array_merge($result, $this->parse(trim(substr($remaining, 1)), $element)); |
|
82 | + } |
|
75 | 83 | return $result; |
76 | 84 | } |
77 | 85 | |
@@ -79,8 +87,9 @@ discard block |
||
79 | 87 | $pos = $start+1; |
80 | 88 | $end = 0; |
81 | 89 | while ($end = strpos($string, $char, $pos)) { |
82 | - if ($string[$end-1] === $escape) $pos = $end+1; |
|
83 | - else { |
|
90 | + if ($string[$end-1] === $escape) { |
|
91 | + $pos = $end+1; |
|
92 | + } else { |
|
84 | 93 | break; |
85 | 94 | } |
86 | 95 | } |
@@ -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, $valueParser) as $rule) { |
44 | - if ($rule->shouldRun($this->time)) $this->executeTssRule($rule, $template, $data, $valueParser); |
|
44 | + if ($rule->shouldRun($this->time)) { |
|
45 | + $this->executeTssRule($rule, $template, $data, $valueParser); |
|
46 | + } |
|
45 | 47 | } |
46 | 48 | |
47 | 49 | $result = ['body' => $template->output($document), 'headers' => array_merge($cachedOutput['headers'], $headers)]; |
@@ -58,7 +60,9 @@ discard block |
||
58 | 60 | $formatter->register(new Formatter\Date($locale)); |
59 | 61 | $formatter->register(new Formatter\StringFormatter()); |
60 | 62 | |
61 | - foreach ($this->formatters as $format) $formatter->register($format); |
|
63 | + foreach ($this->formatters as $format) { |
|
64 | + $formatter->register($format); |
|
65 | + } |
|
62 | 66 | |
63 | 67 | $this->registerProperty('content', new Property\Content($data, $headers, $formatter)); |
64 | 68 | $this->registerProperty('repeat', new Property\Repeat($data)); |
@@ -76,7 +80,9 @@ discard block |
||
76 | 80 | private function executeTssRule($rule, $template, $data, $valueParser) { |
77 | 81 | $rule->touch(); |
78 | 82 | $hook = new Hook\Rule($rule->properties, new Hook\PseudoMatcher($rule->pseudo, $data), $valueParser); |
79 | - foreach ($this->registeredProperties as $name => $property) $hook->registerProperty($name, $property); |
|
83 | + foreach ($this->registeredProperties as $name => $property) { |
|
84 | + $hook->registerProperty($name, $property); |
|
85 | + } |
|
80 | 86 | $template->addHook($rule->query, $hook); |
81 | 87 | } |
82 | 88 | |
@@ -85,8 +91,9 @@ discard block |
||
85 | 91 | if (trim($this->template)[0] !== '<') { |
86 | 92 | $xml = $this->cache->load($this->template, filemtime($this->template)); |
87 | 93 | return $xml ? $xml : ['body' => file_get_contents($this->template), 'headers' => []]; |
94 | + } else { |
|
95 | + return ['body' => $this->template, 'headers' => []]; |
|
88 | 96 | } |
89 | - else return ['body' => $this->template, 'headers' => []]; |
|
90 | 97 | } |
91 | 98 | |
92 | 99 | //Load the TSS rules either from a file or as a string |
@@ -100,10 +107,14 @@ discard block |
||
100 | 107 | $key = $this->tss . $template->getPrefix() . $this->baseDir; |
101 | 108 | //Try to load the cached rules, if not set in the cache (or expired) parse the supplied sheet |
102 | 109 | $rules = $this->cache->load($key, filemtime($this->tss)); |
103 | - if (!$rules) return $this->cache->write($key, (new Sheet(file_get_contents($this->tss), $this->baseDir, $valueParser, $template->getPrefix()))->parse()); |
|
104 | - else return $rules; |
|
110 | + if (!$rules) { |
|
111 | + return $this->cache->write($key, (new Sheet(file_get_contents($this->tss), $this->baseDir, $valueParser, $template->getPrefix()))->parse()); |
|
112 | + } else { |
|
113 | + return $rules; |
|
114 | + } |
|
115 | + } else { |
|
116 | + return (new Sheet($this->tss, $this->baseDir, $valueParser, $template->getPrefix()))->parse(); |
|
105 | 117 | } |
106 | - else return (new Sheet($this->tss, $this->baseDir, $valueParser, $template->getPrefix()))->parse(); |
|
107 | 118 | } |
108 | 119 | |
109 | 120 | public function setCache(\ArrayAccess $cache) { |
@@ -111,9 +122,13 @@ discard block |
||
111 | 122 | } |
112 | 123 | |
113 | 124 | private function getLocale() { |
114 | - if (is_array($this->locale)) return $this->locale; |
|
115 | - 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); |
|
116 | - else return json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'Formatter' . DIRECTORY_SEPARATOR . 'Locale' . DIRECTORY_SEPARATOR . 'enGB.json'), true); |
|
125 | + if (is_array($this->locale)) { |
|
126 | + return $this->locale; |
|
127 | + } else if (strlen($this->locale) > 0) { |
|
128 | + return json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'Formatter' . DIRECTORY_SEPARATOR . 'Locale' . DIRECTORY_SEPARATOR . $this->locale . '.json'), true); |
|
129 | + } else { |
|
130 | + return json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'Formatter' . DIRECTORY_SEPARATOR . 'Locale' . DIRECTORY_SEPARATOR . 'enGB.json'), true); |
|
131 | + } |
|
117 | 132 | } |
118 | 133 | |
119 | 134 | public function registerProperty($name, Property $property) { |
@@ -13,15 +13,15 @@ discard block |
||
13 | 13 | private $valueParser; |
14 | 14 | |
15 | 15 | public function __construct($css, ValueParser $valueParser, $prefix = '') { |
16 | - $this->css = str_replace([' >', '> '],['>', '>'], trim($css)); |
|
16 | + $this->css = str_replace([' >', '> '], ['>', '>'], trim($css)); |
|
17 | 17 | $this->valueParser = $valueParser; |
18 | 18 | $this->translators = [ |
19 | - ' ' => function($string) use ($prefix) { return '//' . $prefix . $string; }, |
|
20 | - '' => function($string) use ($prefix) { return '/' . $prefix . $string; }, |
|
21 | - '>' => function($string) use ($prefix) { return '/' . $prefix . $string; }, |
|
22 | - '#' => function($string) { return '[@id=\'' . $string . '\']'; }, |
|
23 | - '.' => function($string) { return '[contains(concat(\' \', normalize-space(@class), \' \'), \' ' . $string . ' \')]'; }, |
|
24 | - '[' => function($string) { return '[@' . $this->parseAttr($string) . ']'; }, |
|
19 | + ' ' => function($string) use ($prefix) { return '//'.$prefix.$string; }, |
|
20 | + '' => function($string) use ($prefix) { return '/'.$prefix.$string; }, |
|
21 | + '>' => function($string) use ($prefix) { return '/'.$prefix.$string; }, |
|
22 | + '#' => function($string) { return '[@id=\''.$string.'\']'; }, |
|
23 | + '.' => function($string) { return '[contains(concat(\' \', normalize-space(@class), \' \'), \' '.$string.' \')]'; }, |
|
24 | + '[' => function($string) { return '[@'.$this->parseAttr($string).']'; }, |
|
25 | 25 | ']' => function() { return ''; } |
26 | 26 | ]; |
27 | 27 | } |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | $parts = explode($comparator, $attr); |
41 | 41 | |
42 | 42 | foreach ($parts as &$part) $part = implode('', $this->valueParser->parse($part)); |
43 | - if (isset($parts[1])) $parts[1] = '"' . $parts[1] . '"'; |
|
43 | + if (isset($parts[1])) $parts[1] = '"'.$parts[1].'"'; |
|
44 | 44 | return implode($comparator, $parts); |
45 | 45 | } |
46 | 46 | } |
@@ -39,8 +39,12 @@ discard block |
||
39 | 39 | if (strpos($attr, $comparator) !== false) { |
40 | 40 | $parts = explode($comparator, $attr); |
41 | 41 | |
42 | - foreach ($parts as &$part) $part = implode('', $this->valueParser->parse($part)); |
|
43 | - if (isset($parts[1])) $parts[1] = '"' . $parts[1] . '"'; |
|
42 | + foreach ($parts as &$part) { |
|
43 | + $part = implode('', $this->valueParser->parse($part)); |
|
44 | + } |
|
45 | + if (isset($parts[1])) { |
|
46 | + $parts[1] = '"' . $parts[1] . '"'; |
|
47 | + } |
|
44 | 48 | return implode($comparator, $parts); |
45 | 49 | } |
46 | 50 | } |
@@ -59,8 +63,9 @@ discard block |
||
59 | 63 | $selector = $this->createSelector(); |
60 | 64 | $selector->type = $css[$i]; |
61 | 65 | $selectors[] = $selector; |
66 | + } else { |
|
67 | + $selector->string .= $css[$i]; |
|
62 | 68 | } |
63 | - else $selector->string .= $css[$i]; |
|
64 | 69 | } |
65 | 70 | return $selectors; |
66 | 71 | } |
@@ -71,7 +76,9 @@ discard block |
||
71 | 76 | $this->depth = count($selectors); |
72 | 77 | $xpath = '/'; |
73 | 78 | foreach ($selectors as $selector) { |
74 | - if (isset($this->translators[$selector->type])) $xpath .= $this->translators[$selector->type]($selector->string); |
|
79 | + if (isset($this->translators[$selector->type])) { |
|
80 | + $xpath .= $this->translators[$selector->type]($selector->string); |
|
81 | + } |
|
75 | 82 | } |
76 | 83 | |
77 | 84 | $xpath = str_replace('/[', '/*[', $xpath); |
@@ -20,11 +20,15 @@ discard block |
||
20 | 20 | |
21 | 21 | public function run(\DomElement $element) { |
22 | 22 | //Don't run if there's a pseudo element like nth-child() and this element doesn't match it |
23 | - if (!$this->pseudoMatcher->matches($element)) return; |
|
23 | + if (!$this->pseudoMatcher->matches($element)) { |
|
24 | + return; |
|
25 | + } |
|
24 | 26 | |
25 | 27 | foreach ($this->rules as $name => $value) { |
26 | 28 | $result = $this->callProperty($name, $element, $this->valueParser->parse(trim($value), $element)); |
27 | - if ($result === false) break; |
|
29 | + if ($result === false) { |
|
30 | + break; |
|
31 | + } |
|
28 | 32 | } |
29 | 33 | } |
30 | 34 | |
@@ -45,7 +49,9 @@ discard block |
||
45 | 49 | } |
46 | 50 | |
47 | 51 | private function callProperty($name, $element, $value) { |
48 | - if (isset($this->properties[$name])) return $this->properties[$name]->run($value, $element, $this); |
|
52 | + if (isset($this->properties[$name])) { |
|
53 | + return $this->properties[$name]->run($value, $element, $this); |
|
54 | + } |
|
49 | 55 | return false; |
50 | 56 | } |
51 | 57 |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | |
29 | 29 | $selector = trim(substr($this->tss, $pos, $next-$pos)); |
30 | 30 | $rule = $this->cssToRule($selector, count($rules)); |
31 | - $pos = strpos($this->tss, '}', $next)+1; |
|
31 | + $pos = strpos($this->tss, '}', $next)+1; |
|
32 | 32 | $rule->properties = $this->getProperties(trim(substr($this->tss, $next+1, $pos-2-$next))); |
33 | 33 | $rules = $this->writeRule($rules, $selector, $rule); |
34 | 34 | } |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | private function processingInstructions($tss, $pos, $next) { |
55 | 55 | $rules = []; |
56 | 56 | while (($atPos = strpos($tss, '@', $pos)) !== false) { |
57 | - if ($atPos <= (int) $next) { |
|
57 | + if ($atPos <= (int) $next) { |
|
58 | 58 | $spacePos = strpos($tss, ' ', $atPos); |
59 | 59 | $funcName = substr($tss, $atPos+1, $spacePos-$atPos-1); |
60 | 60 | $pos = strpos($tss, ';', $spacePos); |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | } |
71 | 71 | |
72 | 72 | private function import($args) { |
73 | - $sheet = new Sheet(file_get_contents($this->baseDir . trim($args, '\'" ')), $this->baseDir, $this->valueParser, $this->prefix); |
|
73 | + $sheet = new Sheet(file_get_contents($this->baseDir.trim($args, '\'" ')), $this->baseDir, $this->valueParser, $this->prefix); |
|
74 | 74 | return $sheet->parse(); |
75 | 75 | } |
76 | 76 |