@@ -40,7 +40,7 @@ |
||
40 | 40 | |
41 | 41 | private function pseudoBefore($value, $element, $rule) { |
42 | 42 | if (in_array('before', $rule->getPseudoMatcher()->getPseudo())) { |
43 | - $element->firstChild->nodeValue = implode('', $value) . $element->firstChild->nodeValue; |
|
43 | + $element->firstChild->nodeValue = implode('', $value).$element->firstChild->nodeValue; |
|
44 | 44 | return true; |
45 | 45 | } |
46 | 46 | } |
@@ -18,15 +18,20 @@ discard block |
||
18 | 18 | } |
19 | 19 | |
20 | 20 | public function run($value, \DomElement $element, \Transphporm\Hook\PropertyHook $rule) { |
21 | - if ($element->getAttribute('transphporm') === 'remove') return; |
|
21 | + if ($element->getAttribute('transphporm') === 'remove') { |
|
22 | + return; |
|
23 | + } |
|
22 | 24 | |
23 | 25 | $value = $this->formatter->format($value, $rule->getRules()); |
24 | 26 | if (!$this->processPseudo($value, $element, $rule)) { |
25 | 27 | //Remove the current contents |
26 | 28 | $this->removeAllChildren($element); |
27 | 29 | //Now make a text node |
28 | - if ($this->getContentMode($rule->getRules()) === 'replace') $this->replaceContent($element, $value); |
|
29 | - else $this->appendContent($element, $value); |
|
30 | + if ($this->getContentMode($rule->getRules()) === 'replace') { |
|
31 | + $this->replaceContent($element, $value); |
|
32 | + } else { |
|
33 | + $this->appendContent($element, $value); |
|
34 | + } |
|
30 | 35 | } |
31 | 36 | } |
32 | 37 | |
@@ -92,6 +97,8 @@ discard block |
||
92 | 97 | } |
93 | 98 | |
94 | 99 | private function removeAllChildren($element) { |
95 | - while ($element->hasChildNodes()) $element->removeChild($element->firstChild); |
|
100 | + while ($element->hasChildNodes()) { |
|
101 | + $element->removeChild($element->firstChild); |
|
102 | + } |
|
96 | 103 | } |
97 | 104 | } |
98 | 105 | \ No newline at end of file |
@@ -13,7 +13,9 @@ discard block |
||
13 | 13 | } |
14 | 14 | |
15 | 15 | public function run($value, \DomElement $element, \Transphporm\Hook\Rule $rule) { |
16 | - if ($element->getAttribute('transphporm') === 'added') return $element->parentNode->removeChild($element); |
|
16 | + if ($element->getAttribute('transphporm') === 'added') { |
|
17 | + return $element->parentNode->removeChild($element); |
|
18 | + } |
|
17 | 19 | |
18 | 20 | foreach ($value as $key => $iteration) { |
19 | 21 | $clone = $element->cloneNode(true); |
@@ -37,7 +39,9 @@ discard block |
||
37 | 39 | |
38 | 40 | private function createHook($newRules, $rule) { |
39 | 41 | $hook = new \Transphporm\Hook\Rule($newRules, $rule->getPseudoMatcher(), $this->data); |
40 | - foreach ($rule->getProperties() as $name => $property) $hook->registerProperty($name, $property); |
|
42 | + foreach ($rule->getProperties() as $name => $property) { |
|
43 | + $hook->registerProperty($name, $property); |
|
44 | + } |
|
41 | 45 | return $hook; |
42 | 46 | } |
43 | 47 | } |
44 | 48 | \ No newline at end of file |
@@ -35,6 +35,9 @@ |
||
35 | 35 | return false; |
36 | 36 | } |
37 | 37 | |
38 | + /** |
|
39 | + * @param \Transphporm\Hook\PropertyHook $rule |
|
40 | + */ |
|
38 | 41 | private function createHook($newRules, $rule) { |
39 | 42 | $hook = new \Transphporm\Hook\PropertyHook($newRules, $rule->getPseudoMatcher(), new \Transphporm\Parser\Value($this->data)); |
40 | 43 | foreach ($rule->getProperties() as $name => $property) $hook->registerProperty($name, $property); |
@@ -12,7 +12,7 @@ |
||
12 | 12 | $this->data = $data; |
13 | 13 | } |
14 | 14 | |
15 | - public function run($value, \DomElement $element, \Transphporm\Hook\PropertyHook $rule) { |
|
15 | + public function run($value, \DomElement $element, \Transphporm\Hook\PropertyHook $rule) { |
|
16 | 16 | if ($element->getAttribute('transphporm') === 'added') return $element->parentNode->removeChild($element); |
17 | 17 | |
18 | 18 | foreach ($value as $key => $iteration) { |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | |
37 | 37 | $cachedOutput = $this->loadTemplate(); |
38 | 38 | //To be a valid XML document it must have a root element, automatically wrap it in <template> to ensure it does |
39 | - $template = new Template($this->isValidDoc($cachedOutput['body']) ? str_ireplace('<!doctype', '<!DOCTYPE', $cachedOutput['body']) : '<template>' . $cachedOutput['body'] . '</template>' ); |
|
39 | + $template = new Template($this->isValidDoc($cachedOutput['body']) ? str_ireplace('<!doctype', '<!DOCTYPE', $cachedOutput['body']) : '<template>'.$cachedOutput['body'].'</template>'); |
|
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) { |
@@ -92,11 +92,11 @@ discard block |
||
92 | 92 | //N.b. only files can be cached |
93 | 93 | private function getRules($template) { |
94 | 94 | if (is_file($this->tss)) { |
95 | - $this->baseDir = dirname(realpath($this->tss)) . DIRECTORY_SEPARATOR; |
|
95 | + $this->baseDir = dirname(realpath($this->tss)).DIRECTORY_SEPARATOR; |
|
96 | 96 | //The cache for the key: the filename and template prefix |
97 | 97 | //Each template may have a different prefix which changes the parsed TSS, |
98 | 98 | //Because of this the cache needs to be generated for each template prefix. |
99 | - $key = $this->tss . $template->getPrefix() . $this->baseDir; |
|
99 | + $key = $this->tss.$template->getPrefix().$this->baseDir; |
|
100 | 100 | //Try to load the cached rules, if not set in the cache (or expired) parse the supplied sheet |
101 | 101 | $rules = $this->cache->load($key, filemtime($this->tss)); |
102 | 102 | if (!$rules) return $this->cache->write($key, (new Sheet(file_get_contents($this->tss), $this->baseDir, $template->getPrefix()))->parse()); |
@@ -111,8 +111,8 @@ discard block |
||
111 | 111 | |
112 | 112 | private function getLocale() { |
113 | 113 | if (is_array($this->locale)) return $this->locale; |
114 | - 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); |
|
115 | - else return json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'Formatter' . DIRECTORY_SEPARATOR . 'Locale' . DIRECTORY_SEPARATOR . 'enGB.json'), true); |
|
114 | + 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); |
|
115 | + else return json_decode(file_get_contents(__DIR__.DIRECTORY_SEPARATOR.'Formatter'.DIRECTORY_SEPARATOR.'Locale'.DIRECTORY_SEPARATOR.'enGB.json'), true); |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | public function registerProperty($name, Property $property) { |
@@ -52,7 +52,9 @@ discard block |
||
52 | 52 | private function processRules($template, $data) { |
53 | 53 | $valueParser = new Parser\Value($data); |
54 | 54 | foreach ($this->getRules($template, $valueParser) as $rule) { |
55 | - if ($rule->shouldRun($this->time)) $this->executeTssRule($rule, $template, $data, $valueParser); |
|
55 | + if ($rule->shouldRun($this->time)) { |
|
56 | + $this->executeTssRule($rule, $template, $data, $valueParser); |
|
57 | + } |
|
56 | 58 | } |
57 | 59 | } |
58 | 60 | |
@@ -66,7 +68,9 @@ discard block |
||
66 | 68 | private function executeTssRule($rule, $template, $data, $valueParser) { |
67 | 69 | $rule->touch(); |
68 | 70 | $hook = new Hook\PropertyHook($rule->properties, new Hook\PseudoMatcher($rule->pseudo, $data), $valueParser); |
69 | - foreach ($this->registeredProperties as $name => $property) $hook->registerProperty($name, $property); |
|
71 | + foreach ($this->registeredProperties as $name => $property) { |
|
72 | + $hook->registerProperty($name, $property); |
|
73 | + } |
|
70 | 74 | $template->addHook($rule->query, $hook); |
71 | 75 | } |
72 | 76 | |
@@ -75,8 +79,9 @@ discard block |
||
75 | 79 | if (trim($this->template)[0] !== '<') { |
76 | 80 | $xml = $this->cache->load($this->template, filemtime($this->template)); |
77 | 81 | return $xml ? $xml : ['body' => file_get_contents($this->template), 'headers' => []]; |
82 | + } else { |
|
83 | + return ['body' => $this->template, 'headers' => []]; |
|
78 | 84 | } |
79 | - else return ['body' => $this->template, 'headers' => []]; |
|
80 | 85 | } |
81 | 86 | |
82 | 87 | //Load the TSS rules either from a file or as a string |
@@ -90,10 +95,14 @@ discard block |
||
90 | 95 | $key = $this->tss . $template->getPrefix() . $this->baseDir; |
91 | 96 | //Try to load the cached rules, if not set in the cache (or expired) parse the supplied sheet |
92 | 97 | $rules = $this->cache->load($key, filemtime($this->tss)); |
93 | - if (!$rules) return $this->cache->write($key, (new Parser\Sheet(file_get_contents($this->tss), $this->baseDir, $valueParser, $template->getPrefix()))->parse()); |
|
94 | - else return $rules; |
|
98 | + if (!$rules) { |
|
99 | + return $this->cache->write($key, (new Parser\Sheet(file_get_contents($this->tss), $this->baseDir, $valueParser, $template->getPrefix()))->parse()); |
|
100 | + } else { |
|
101 | + return $rules; |
|
102 | + } |
|
103 | + } else { |
|
104 | + return (new Parser\Sheet($this->tss, $this->baseDir, $valueParser, $template->getPrefix()))->parse(); |
|
95 | 105 | } |
96 | - else return (new Parser\Sheet($this->tss, $this->baseDir, $valueParser, $template->getPrefix()))->parse(); |
|
97 | 106 | } |
98 | 107 | |
99 | 108 | public function setCache(\ArrayAccess $cache) { |
@@ -101,9 +110,13 @@ discard block |
||
101 | 110 | } |
102 | 111 | |
103 | 112 | private function getLocale() { |
104 | - if (is_array($this->locale)) return $this->locale; |
|
105 | - 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); |
|
106 | - else return json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'Formatter' . DIRECTORY_SEPARATOR . 'Locale' . DIRECTORY_SEPARATOR . 'enGB.json'), true); |
|
113 | + if (is_array($this->locale)) { |
|
114 | + return $this->locale; |
|
115 | + } else if (strlen($this->locale) > 0) { |
|
116 | + return json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'Formatter' . DIRECTORY_SEPARATOR . 'Locale' . DIRECTORY_SEPARATOR . $this->locale . '.json'), true); |
|
117 | + } else { |
|
118 | + return json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'Formatter' . DIRECTORY_SEPARATOR . 'Locale' . DIRECTORY_SEPARATOR . 'enGB.json'), true); |
|
119 | + } |
|
107 | 120 | } |
108 | 121 | |
109 | 122 | public function registerProperty($name, Property $property) { |
@@ -12,6 +12,9 @@ discard block |
||
12 | 12 | private $prefix; |
13 | 13 | private $valueParser; |
14 | 14 | |
15 | + /** |
|
16 | + * @param string $tss |
|
17 | + */ |
|
15 | 18 | public function __construct($tss, $baseDir, Value $valueParser, $prefix = '') { |
16 | 19 | $this->tss = $this->stripComments($tss); |
17 | 20 | $this->baseDir = $baseDir; |
@@ -38,12 +41,20 @@ discard block |
||
38 | 41 | return $rules; |
39 | 42 | } |
40 | 43 | |
44 | + /** |
|
45 | + * @param string $selector |
|
46 | + * @param integer $index |
|
47 | + */ |
|
41 | 48 | private function CssToRule($selector, $index) { |
42 | 49 | $xPath = new CssToXpath($selector, $this->valueParser, $this->prefix); |
43 | 50 | $rule = new \Transphporm\Rule($xPath->getXpath(), $xPath->getPseudo(), $xPath->getDepth(), $index++); |
44 | 51 | return $rule; |
45 | 52 | } |
46 | 53 | |
54 | + /** |
|
55 | + * @param string $selector |
|
56 | + * @param \Transphporm\Rule $newRule |
|
57 | + */ |
|
47 | 58 | private function writeRule($rules, $selector, $newRule) { |
48 | 59 | if (isset($rules[$selector])) { |
49 | 60 | $newRule->properties = array_merge($rules[$selector]->properties, $newRule->properties); |
@@ -54,6 +65,10 @@ discard block |
||
54 | 65 | return $rules; |
55 | 66 | } |
56 | 67 | |
68 | + /** |
|
69 | + * @param integer $pos |
|
70 | + * @param integer $next |
|
71 | + */ |
|
57 | 72 | private function processingInstructions($tss, $pos, $next) { |
58 | 73 | $rules = []; |
59 | 74 | while (($atPos = strpos($tss, '@', $pos)) !== false) { |
@@ -94,6 +109,9 @@ discard block |
||
94 | 109 | return $str; |
95 | 110 | } |
96 | 111 | |
112 | + /** |
|
113 | + * @param string $str |
|
114 | + */ |
|
97 | 115 | private function getProperties($str) { |
98 | 116 | $stringExtractor = new StringExtractor($str); |
99 | 117 | $rules = explode(';', $stringExtractor); |
@@ -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 |
@@ -33,7 +33,9 @@ discard block |
||
33 | 33 | $rules = $this->writeRule($rules, $selector, $rule); |
34 | 34 | } |
35 | 35 | //there may be processing instructions at the end |
36 | - if ($processing = $this->processingInstructions($this->tss, $pos, strlen($this->tss))) $rules = array_merge($processing['rules'], $rules); |
|
36 | + if ($processing = $this->processingInstructions($this->tss, $pos, strlen($this->tss))) { |
|
37 | + $rules = array_merge($processing['rules'], $rules); |
|
38 | + } |
|
37 | 39 | usort($rules, [$this, 'sortRules']); |
38 | 40 | return $rules; |
39 | 41 | } |
@@ -63,8 +65,7 @@ discard block |
||
63 | 65 | $pos = strpos($tss, ';', $spacePos); |
64 | 66 | $args = substr($tss, $spacePos+1, $pos-$spacePos-1); |
65 | 67 | $rules = array_merge($rules, $this->$funcName($args)); |
66 | - } |
|
67 | - else { |
|
68 | + } else { |
|
68 | 69 | break; |
69 | 70 | } |
70 | 71 | } |
@@ -79,7 +80,9 @@ discard block |
||
79 | 80 | |
80 | 81 | private function sortRules($a, $b) { |
81 | 82 | //If they have the same depth, compare on index |
82 | - if ($a->depth === $b->depth) return $a->index < $b->index ? -1 : 1; |
|
83 | + if ($a->depth === $b->depth) { |
|
84 | + return $a->index < $b->index ? -1 : 1; |
|
85 | + } |
|
83 | 86 | |
84 | 87 | return ($a->depth < $b->depth) ? -1 : 1; |
85 | 88 | } |
@@ -100,7 +103,9 @@ discard block |
||
100 | 103 | $return = []; |
101 | 104 | |
102 | 105 | foreach ($rules as $rule) { |
103 | - if (trim($rule) === '') continue; |
|
106 | + if (trim($rule) === '') { |
|
107 | + continue; |
|
108 | + } |
|
104 | 109 | $parts = explode(':', $rule, 2); |
105 | 110 | |
106 | 111 | $parts[1] = $stringExtractor->rebuild($parts[1]); |
@@ -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; |
@@ -64,7 +64,7 @@ |
||
64 | 64 | $finalPos = $this->findMatchingPos($str, $marker); |
65 | 65 | $string = substr($str, 1, $finalPos-1); |
66 | 66 | //Now remove escape characters |
67 | - return str_replace('\\' . $marker, $marker, $string); |
|
67 | + return str_replace('\\'.$marker, $marker, $string); |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | private function parseFunction($function) { |
@@ -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 | } |
@@ -20,7 +20,9 @@ |
||
20 | 20 | $formatter->register(new Formatter\Date($locale)); |
21 | 21 | $formatter->register(new Formatter\StringFormatter()); |
22 | 22 | |
23 | - foreach ($formatters as $format) $formatter->register($format); |
|
23 | + foreach ($formatters as $format) { |
|
24 | + $formatter->register($format); |
|
25 | + } |
|
24 | 26 | |
25 | 27 | $this->builder->registerProperty('content', new Property\Content($data, $headers, $formatter)); |
26 | 28 | $this->builder->registerProperty('repeat', new Property\Repeat($data)); |
@@ -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 |
@@ -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 | } |
@@ -41,7 +41,9 @@ discard block |
||
41 | 41 | $parts = array_map(function($val) { |
42 | 42 | return implode($this->valueParser->parse($val)); |
43 | 43 | }, $parts); |
44 | - if (isset($parts[1])) $parts[1] = '"' . $parts[1] . '"'; |
|
44 | + if (isset($parts[1])) { |
|
45 | + $parts[1] = '"' . $parts[1] . '"'; |
|
46 | + } |
|
45 | 47 | return implode($comparator, $parts); |
46 | 48 | } |
47 | 49 | } |
@@ -60,8 +62,9 @@ discard block |
||
60 | 62 | $selector = $this->createSelector(); |
61 | 63 | $selector->type = $css[$i]; |
62 | 64 | $selectors[] = $selector; |
65 | + } else { |
|
66 | + $selector->string .= $css[$i]; |
|
63 | 67 | } |
64 | - else $selector->string .= $css[$i]; |
|
65 | 68 | } |
66 | 69 | return $selectors; |
67 | 70 | } |
@@ -72,7 +75,9 @@ discard block |
||
72 | 75 | $this->depth = count($selectors); |
73 | 76 | $xpath = '/'; |
74 | 77 | foreach ($selectors as $selector) { |
75 | - if (isset($this->translators[$selector->type])) $xpath .= $this->translators[$selector->type]($selector->string); |
|
78 | + if (isset($this->translators[$selector->type])) { |
|
79 | + $xpath .= $this->translators[$selector->type]($selector->string); |
|
80 | + } |
|
76 | 81 | } |
77 | 82 | |
78 | 83 | $xpath = str_replace('/[', '/*[', $xpath); |
@@ -17,8 +17,8 @@ |
||
17 | 17 | while (($pos = strpos($str, '"', $pos+1)) !== false) { |
18 | 18 | $end = strpos($str, '"', $pos+1); |
19 | 19 | while ($str[$end-1] == '\\') $end = strpos($str, '"', $end+1); |
20 | - $strings['$+STR' . ++$num] = substr($str, $pos, $end-$pos+1); |
|
21 | - $str = substr_replace($str, '$+STR' . $num, $pos, $end-$pos+1); |
|
20 | + $strings['$+STR'.++$num] = substr($str, $pos, $end-$pos+1); |
|
21 | + $str = substr_replace($str, '$+STR'.$num, $pos, $end-$pos+1); |
|
22 | 22 | } |
23 | 23 | |
24 | 24 | return [$str, $strings]; |
@@ -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 | } |