@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | private $rules; |
11 | 11 | private $configLine; |
12 | 12 | private $file; |
13 | - private $filePath; |
|
13 | + private $filePath; |
|
14 | 14 | private $line; |
15 | 15 | private $valueParser; |
16 | 16 | private $pseudoMatcher; |
@@ -18,11 +18,11 @@ discard block |
||
18 | 18 | private $functionSet; |
19 | 19 | |
20 | 20 | public function __construct(array $rules, &$configLine, $file, $line, PseudoMatcher $pseudoMatcher, |
21 | - \Transphporm\Parser\Value $valueParser, \Transphporm\FunctionSet $functionSet, \Transphporm\FilePath $filePath) { |
|
21 | + \Transphporm\Parser\Value $valueParser, \Transphporm\FunctionSet $functionSet, \Transphporm\FilePath $filePath) { |
|
22 | 22 | $this->rules = $rules; |
23 | 23 | $this->configLine = &$configLine; |
24 | 24 | $this->file = $file; |
25 | - $this->filePath = $filePath; |
|
25 | + $this->filePath = $filePath; |
|
26 | 26 | $this->line = $line; |
27 | 27 | $this->valueParser = $valueParser; |
28 | 28 | $this->pseudoMatcher = $pseudoMatcher; |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | |
32 | 32 | public function run(\DomElement $element) { |
33 | 33 | //Set the baseDir so that all files for this rule are relative to the file it came from |
34 | - if ($this->file !== null) $this->filePath->setBaseDir(dirname(realpath($this->file))); |
|
34 | + if ($this->file !== null) $this->filePath->setBaseDir(dirname(realpath($this->file))); |
|
35 | 35 | $this->functionSet->setElement($element); |
36 | 36 | $this->configLine = $this->line; |
37 | 37 | try { |
@@ -31,15 +31,18 @@ discard block |
||
31 | 31 | |
32 | 32 | public function run(\DomElement $element) { |
33 | 33 | //Set the baseDir so that all files for this rule are relative to the file it came from |
34 | - if ($this->file !== null) $this->filePath->setBaseDir(dirname(realpath($this->file))); |
|
34 | + if ($this->file !== null) { |
|
35 | + $this->filePath->setBaseDir(dirname(realpath($this->file))); |
|
36 | + } |
|
35 | 37 | $this->functionSet->setElement($element); |
36 | 38 | $this->configLine = $this->line; |
37 | 39 | try { |
38 | 40 | //Don't run if there's a pseudo element like nth-child() and this element doesn't match it |
39 | - if (!$this->pseudoMatcher->matches($element)) return; |
|
41 | + if (!$this->pseudoMatcher->matches($element)) { |
|
42 | + return; |
|
43 | + } |
|
40 | 44 | $this->callProperties($element); |
41 | - } |
|
42 | - catch (\Transphporm\RunException $e) { |
|
45 | + } catch (\Transphporm\RunException $e) { |
|
43 | 46 | throw new \Transphporm\Exception($e, $this->file, $this->line); |
44 | 47 | } |
45 | 48 | } |
@@ -50,7 +53,9 @@ discard block |
||
50 | 53 | private function callProperties($element) { |
51 | 54 | foreach ($this->rules as $name => $value) { |
52 | 55 | $result = $this->callProperty($name, $element, $this->getArgs($value)); |
53 | - if ($result === false) break; |
|
56 | + if ($result === false) { |
|
57 | + break; |
|
58 | + } |
|
54 | 59 | } |
55 | 60 | } |
56 | 61 | private function getArgs($value) { |
@@ -65,9 +70,10 @@ discard block |
||
65 | 70 | if (isset($this->properties[$name])) { |
66 | 71 | try { |
67 | 72 | return $this->properties[$name]->run($value, $element, $this->rules, $this->pseudoMatcher, $this->properties); |
68 | - } |
|
69 | - catch (\Exception $e) { |
|
70 | - if ($e instanceof \Transphporm\RunException) throw $e; |
|
73 | + } catch (\Exception $e) { |
|
74 | + if ($e instanceof \Transphporm\RunException) { |
|
75 | + throw $e; |
|
76 | + } |
|
71 | 77 | throw new \Transphporm\RunException(\Transphporm\Exception::PROPERTY, $name, $e); |
72 | 78 | } |
73 | 79 | } |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | /** Converts $val into a \DateTime object if it's not already */ |
17 | 17 | private function getDate($val) { |
18 | 18 | $tz = new \DateTimeZone($this->locale['timezone']); |
19 | - $date = $val instanceof \DateTimeInterface ? $val : new \DateTime($val, $tz); |
|
19 | + $date = $val instanceof \DateTimeInterface ? $val : new \DateTime($val, $tz); |
|
20 | 20 | $date->setTimeZone($tz); |
21 | 21 | return $date; |
22 | 22 | } |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | |
36 | 36 | /** Formats \DateTime as Date and Time using formats from $locale */ |
37 | 37 | public function dateTime($val) { |
38 | - return $this->date($val, $this->locale['date_format'] . ' ' . $this->locale['time_format']); |
|
38 | + return $this->date($val, $this->locale['date_format'].' '.$this->locale['time_format']); |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | /** Generates relative time offsets based on system clock. e.g "10 minutes ago" or "In 6 months" |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | $diff = $now->diff($date); |
48 | 48 | |
49 | 49 | |
50 | - $diffDays = $diff->invert === 1 ? $diff->days : 0- $diff->days; |
|
50 | + $diffDays = $diff->invert === 1 ? $diff->days : 0-$diff->days; |
|
51 | 51 | |
52 | 52 | if ($diffDays !== 0) return $this->dayOffset($diffDays); |
53 | 53 | else return $this->timeOffset($diff); |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | |
76 | 76 | /** Gets date ranges to represent uses of weeks/months/days/etc */ |
77 | 77 | private function getRanges($strings) { |
78 | - $ranges = [ |
|
78 | + $ranges = [ |
|
79 | 79 | [1, 1, $strings['yesterday'], 1, ''], |
80 | 80 | [1, 13, $strings['past'], 1, 'days'], |
81 | 81 | [13, 28, $strings['past'], 7, 'weeks'], |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | |
95 | 95 | /** Converts "week" to "weeks", "month" to "months" etc when plural is required using language from $locale */ |
96 | 96 | private function getPlural($strings, $num, $interval) { |
97 | - if ($interval !== '') return $num == 1 ? $strings[$interval . '_singular'] : $strings[$interval . '_plural']; |
|
97 | + if ($interval !== '') return $num == 1 ? $strings[$interval.'_singular'] : $strings[$interval.'_plural']; |
|
98 | 98 | else return ''; |
99 | 99 | } |
100 | 100 |
@@ -92,10 +92,10 @@ |
||
92 | 92 | return $ranges; |
93 | 93 | } |
94 | 94 | |
95 | - private function add2DayRanges(&$ranges, $property, $when) { |
|
96 | - $rangeVal = $when === "before" ? 2 : -2; |
|
97 | - array_unshift($ranges, [$rangeVal, $rangeVal, $property, 1, '']); |
|
98 | - } |
|
95 | + private function add2DayRanges(&$ranges, $property, $when) { |
|
96 | + $rangeVal = $when === "before" ? 2 : -2; |
|
97 | + array_unshift($ranges, [$rangeVal, $rangeVal, $property, 1, '']); |
|
98 | + } |
|
99 | 99 | |
100 | 100 | /** Converts "week" to "weeks", "month" to "months" etc when plural is required using language from $locale */ |
101 | 101 | private function getPlural($strings, $num, $interval) { |
@@ -49,8 +49,11 @@ discard block |
||
49 | 49 | |
50 | 50 | $diffDays = $diff->invert === 1 ? $diff->days : 0- $diff->days; |
51 | 51 | |
52 | - if ($diffDays !== 0) return $this->dayOffset($diffDays); |
|
53 | - else return $this->timeOffset($diff); |
|
52 | + if ($diffDays !== 0) { |
|
53 | + return $this->dayOffset($diffDays); |
|
54 | + } else { |
|
55 | + return $this->timeOffset($diff); |
|
56 | + } |
|
54 | 57 | } |
55 | 58 | |
56 | 59 | /** Calculates offset in hours/minutes/seconds */ |
@@ -87,8 +90,12 @@ discard block |
||
87 | 90 | [-365, -28, $strings['future'], 28, 'months'], |
88 | 91 | [-999999, -365, $strings['future'], 365, 'years'], |
89 | 92 | ]; |
90 | - if (isset($strings['day_before_yesterday'])) $this->add2DayRanges($ranges, $strings['day_before_yesterday'], "before"); |
|
91 | - if (isset($strings['day_after_tomorrow'])) $this->add2DayRanges($ranges, $strings['day_after_tomorrow'], "after"); |
|
93 | + if (isset($strings['day_before_yesterday'])) { |
|
94 | + $this->add2DayRanges($ranges, $strings['day_before_yesterday'], "before"); |
|
95 | + } |
|
96 | + if (isset($strings['day_after_tomorrow'])) { |
|
97 | + $this->add2DayRanges($ranges, $strings['day_after_tomorrow'], "after"); |
|
98 | + } |
|
92 | 99 | return $ranges; |
93 | 100 | } |
94 | 101 | |
@@ -99,8 +106,11 @@ discard block |
||
99 | 106 | |
100 | 107 | /** Converts "week" to "weeks", "month" to "months" etc when plural is required using language from $locale */ |
101 | 108 | private function getPlural($strings, $num, $interval) { |
102 | - if ($interval !== '') return $num == 1 ? $strings[$interval . '_singular'] : $strings[$interval . '_plural']; |
|
103 | - else return ''; |
|
109 | + if ($interval !== '') { |
|
110 | + return $num == 1 ? $strings[$interval . '_singular'] : $strings[$interval . '_plural']; |
|
111 | + } else { |
|
112 | + return ''; |
|
113 | + } |
|
104 | 114 | } |
105 | 115 | |
106 | 116 | /** Calculates offset in days/weeks/month/years */ |
@@ -69,7 +69,7 @@ |
||
69 | 69 | |
70 | 70 | public function extract($last, $autoLookup, $traversing) { |
71 | 71 | $value = $this->read($last); |
72 | - if ($value !== null && ($autoLookup || $traversing) ) { |
|
72 | + if ($value !== null && ($autoLookup || $traversing)) { |
|
73 | 73 | return $value; |
74 | 74 | } |
75 | 75 | throw new \UnexpectedValueException('Not found'); |
@@ -15,13 +15,17 @@ discard block |
||
15 | 15 | |
16 | 16 | //Read $key from array, $this->data = $this->data[$key] but also works for objects |
17 | 17 | private function traverseInto($key) { |
18 | - if (isset($this->data->{$key})) $this->data = $this->data->{$key}; |
|
19 | - else if ($this->isArray() && isset($this->data[$key])) $this->data = $this->data[$key]; |
|
18 | + if (isset($this->data->{$key})) { |
|
19 | + $this->data = $this->data->{$key}; |
|
20 | + } else if ($this->isArray() && isset($this->data[$key])) { |
|
21 | + $this->data = $this->data[$key]; |
|
22 | + } |
|
20 | 23 | } |
21 | 24 | |
22 | 25 | public function traverse($key, $result) { |
23 | - if ($key !== null) $this->traverseInto($key); |
|
24 | - else { |
|
26 | + if ($key !== null) { |
|
27 | + $this->traverseInto($key); |
|
28 | + } else { |
|
25 | 29 | //But if the key is null, replace the data structure with the result of the last function call |
26 | 30 | $lastResult = $result->pop(); |
27 | 31 | if ($lastResult) { |
@@ -41,10 +45,14 @@ discard block |
||
41 | 45 | |
42 | 46 | public function read($value) { |
43 | 47 | if ($this->isArray()) { |
44 | - if (isset($this->data[$value])) return $this->data[$value]; |
|
48 | + if (isset($this->data[$value])) { |
|
49 | + return $this->data[$value]; |
|
50 | + } |
|
51 | + } else if (isset($this->data->$value)) { |
|
52 | + return $this->data->$value; |
|
53 | + } else { |
|
54 | + return null; |
|
45 | 55 | } |
46 | - else if (isset($this->data->$value)) return $this->data->$value; |
|
47 | - else return null; |
|
48 | 56 | } |
49 | 57 | |
50 | 58 | public function call($func, $args) { |
@@ -57,14 +65,20 @@ discard block |
||
57 | 65 | |
58 | 66 | public function parseNested($parser, $token, $funcName) { |
59 | 67 | $args = $parser->parseTokens($token['value'], $this->data); |
60 | - if ($args[0] === $this->data) $args = []; |
|
68 | + if ($args[0] === $this->data) { |
|
69 | + $args = []; |
|
70 | + } |
|
61 | 71 | return $this->callFuncOnObject($this->data, $funcName, $args); |
62 | 72 | } |
63 | 73 | |
64 | 74 | private function callFuncOnObject($obj, $func, $args) { |
65 | - if (isset($obj->$func) && is_callable($obj->$func)) return call_user_func_array($obj->$func, $args); |
|
66 | - else if (is_callable([$obj, $func])) return call_user_func_array([$obj, $func], $args); |
|
67 | - else return false; |
|
75 | + if (isset($obj->$func) && is_callable($obj->$func)) { |
|
76 | + return call_user_func_array($obj->$func, $args); |
|
77 | + } else if (is_callable([$obj, $func])) { |
|
78 | + return call_user_func_array([$obj, $func], $args); |
|
79 | + } else { |
|
80 | + return false; |
|
81 | + } |
|
68 | 82 | } |
69 | 83 | |
70 | 84 | public function extract($last, $autoLookup, $traversing) { |
@@ -53,9 +53,9 @@ |
||
53 | 53 | $this->last = $value; |
54 | 54 | } |
55 | 55 | |
56 | - public function makeTraversing() { |
|
57 | - $this->traversing = true; |
|
58 | - } |
|
56 | + public function makeTraversing() { |
|
57 | + $this->traversing = true; |
|
58 | + } |
|
59 | 59 | |
60 | 60 | //Applies the current operation to whatever is in $last based on $mode |
61 | 61 | public function process() { |
@@ -63,8 +63,7 @@ discard block |
||
63 | 63 | try { |
64 | 64 | $value = $this->data->extract($this->last, $this->autoLookup, $this->traversing); |
65 | 65 | $this->result->processValue($value); |
66 | - } |
|
67 | - catch (\UnexpectedValueException $e) { |
|
66 | + } catch (\UnexpectedValueException $e) { |
|
68 | 67 | $this->processLastUnexpected(); |
69 | 68 | } |
70 | 69 | } |
@@ -73,8 +72,7 @@ discard block |
||
73 | 72 | private function processLastUnexpected() { |
74 | 73 | if (!($this->autoLookup || $this->traversing)) { |
75 | 74 | $this->result->processValue($this->last); |
76 | - } |
|
77 | - else { |
|
75 | + } else { |
|
78 | 76 | $this->result->clear(); |
79 | 77 | $this->result->processValue(false); |
80 | 78 | } |
@@ -148,7 +148,7 @@ |
||
148 | 148 | } |
149 | 149 | else $parsedVal = null; |
150 | 150 | |
151 | - $this->result->postProcess($this->data, $val, $parsedVal, $this->allowNullResult); |
|
151 | + $this->result->postProcess($this->data, $val, $parsedVal, $this->allowNullResult); |
|
152 | 152 | |
153 | 153 | $this->last->clear(); |
154 | 154 | } |
@@ -85,7 +85,7 @@ |
||
85 | 85 | if ($lastResult) { |
86 | 86 | $this->last->makeTraversing(); |
87 | 87 | } |
88 | - else if ($this->last->isEmpty()) { |
|
88 | + else if ($this->last->isEmpty()) { |
|
89 | 89 | $this->processString(['value' => '.']); |
90 | 90 | $this->result->setMode(Tokenizer::CONCAT); |
91 | 91 | } |
@@ -58,7 +58,9 @@ discard block |
||
58 | 58 | $this->last = new Last($this->data, $this->result, $this->autoLookup); |
59 | 59 | $this->traversing = false; |
60 | 60 | |
61 | - if (count($tokens) <= 0) return [$data]; |
|
61 | + if (count($tokens) <= 0) { |
|
62 | + return [$data]; |
|
63 | + } |
|
62 | 64 | |
63 | 65 | foreach (new TokenFilterIterator($tokens, [Tokenizer::WHITESPACE, Tokenizer::NEW_LINE]) as $name => $token) { |
64 | 66 | $this->{$this->tokenFuncs[$token['type']]}($token); |
@@ -86,8 +88,7 @@ discard block |
||
86 | 88 | // foo.bar is treated as looking up `bar` in `foo` whereas .foo is treated as the string ".foo" |
87 | 89 | if ($lastResult) { |
88 | 90 | $this->last->makeTraversing(); |
89 | - } |
|
90 | - else if ($this->last->isEmpty()) { |
|
91 | + } else if ($this->last->isEmpty()) { |
|
91 | 92 | $this->processString(['value' => '.']); |
92 | 93 | $this->result->setMode(Tokenizer::CONCAT); |
93 | 94 | } |
@@ -102,11 +103,12 @@ discard block |
||
102 | 103 | private function processSquareBracket($token) { |
103 | 104 | if ($this->hasFunction($this->last->read())) { |
104 | 105 | $this->callTransphpormFunctions($token); |
105 | - } |
|
106 | - else { |
|
106 | + } else { |
|
107 | 107 | $this->last->traverse(); |
108 | 108 | $this->last->set($this->getNewParser()->parseTokens($token['value'], null)[0]); |
109 | - if (!is_bool($this->last->read())) $this->last->makeTraversing(); |
|
109 | + if (!is_bool($this->last->read())) { |
|
110 | + $this->last->makeTraversing(); |
|
111 | + } |
|
110 | 112 | } |
111 | 113 | } |
112 | 114 | |
@@ -129,8 +131,7 @@ discard block |
||
129 | 131 | if ($this->hasFunction($this->last->read()) |
130 | 132 | && !$this->data->methodExists($this->last->read())) { |
131 | 133 | $this->callTransphpormFunctions($token); |
132 | - } |
|
133 | - else { |
|
134 | + } else { |
|
134 | 135 | $this->last->processNested($this->getNewParser(), $token); |
135 | 136 | } |
136 | 137 | } |
@@ -147,8 +148,9 @@ discard block |
||
147 | 148 | $parser = new Value($this->data->getData()); |
148 | 149 | $parsedArr = $parser->parse($val); |
149 | 150 | $parsedVal = isset($parsedArr[0]) ? $parsedArr[0] : null; |
151 | + } else { |
|
152 | + $parsedVal = null; |
|
150 | 153 | } |
151 | - else $parsedVal = null; |
|
152 | 154 | |
153 | 155 | $this->result->postProcess($this->data, $val, $parsedVal, $this->allowNullResult); |
154 | 156 |
@@ -14,7 +14,9 @@ discard block |
||
14 | 14 | } |
15 | 15 | |
16 | 16 | public function run(array $values, \DomElement $element, array $rules, \Transphporm\Hook\PseudoMatcher $pseudoMatcher, array $properties = []) { |
17 | - if (!$this->shouldRun($element)) return false; |
|
17 | + if (!$this->shouldRun($element)) { |
|
18 | + return false; |
|
19 | + } |
|
18 | 20 | |
19 | 21 | $values = $this->formatter->format($values, $rules); |
20 | 22 | |
@@ -22,14 +24,19 @@ discard block |
||
22 | 24 | //Remove the current contents |
23 | 25 | $this->removeAllChildren($element); |
24 | 26 | //Now make a text node |
25 | - if ($this->getContentMode($rules) === 'replace') $this->replaceContent($element, $values); |
|
26 | - else $this->appendContent($element, $values); |
|
27 | + if ($this->getContentMode($rules) === 'replace') { |
|
28 | + $this->replaceContent($element, $values); |
|
29 | + } else { |
|
30 | + $this->appendContent($element, $values); |
|
31 | + } |
|
27 | 32 | } |
28 | 33 | } |
29 | 34 | |
30 | 35 | private function shouldRun($element) { |
31 | 36 | do { |
32 | - if ($element->getAttribute('transphporm') == 'includedtemplate') return false; |
|
37 | + if ($element->getAttribute('transphporm') == 'includedtemplate') { |
|
38 | + return false; |
|
39 | + } |
|
33 | 40 | } |
34 | 41 | while (($element = $element->parentNode) instanceof \DomElement); |
35 | 42 | return true; |
@@ -56,9 +63,10 @@ discard block |
||
56 | 63 | public function getNode($node, $document) { |
57 | 64 | foreach ($node as $n) { |
58 | 65 | if (is_array($n)) { |
59 | - foreach ($this->getNode($n, $document) as $new) yield $new; |
|
60 | - } |
|
61 | - else { |
|
66 | + foreach ($this->getNode($n, $document) as $new) { |
|
67 | + yield $new; |
|
68 | + } |
|
69 | + } else { |
|
62 | 70 | yield $this->convertNode($n, $document); |
63 | 71 | } |
64 | 72 | } |
@@ -69,9 +77,10 @@ discard block |
||
69 | 77 | $new = $document->importNode($node, true); |
70 | 78 | //Removing this might cause problems with caching... |
71 | 79 | //$new->setAttribute('transphporm', 'added'); |
72 | - } |
|
73 | - else { |
|
74 | - if ($node instanceof \DomText) $node = $node->nodeValue; |
|
80 | + } else { |
|
81 | + if ($node instanceof \DomText) { |
|
82 | + $node = $node->nodeValue; |
|
83 | + } |
|
75 | 84 | $new = $document->createElement('text'); |
76 | 85 | |
77 | 86 | $new->appendChild($document->createTextNode($node)); |
@@ -95,6 +104,8 @@ discard block |
||
95 | 104 | } |
96 | 105 | |
97 | 106 | private function removeAllChildren($element) { |
98 | - while ($element->hasChildNodes()) $element->removeChild($element->firstChild); |
|
107 | + while ($element->hasChildNodes()) { |
|
108 | + $element->removeChild($element->firstChild); |
|
109 | + } |
|
99 | 110 | } |
100 | 111 | } |
@@ -68,7 +68,9 @@ discard block |
||
68 | 68 | } |
69 | 69 | |
70 | 70 | public function registerContentPseudo($name, Property\ContentPseudo $pseudo) { |
71 | - if (isset($this->properties['content'])) $this->properties['content']->addContentPseudo($name, $pseudo); |
|
71 | + if (isset($this->properties['content'])) { |
|
72 | + $this->properties['content']->addContentPseudo($name, $pseudo); |
|
73 | + } |
|
72 | 74 | } |
73 | 75 | |
74 | 76 | public function registerPseudo(Pseudo $pseudo) { |
@@ -76,12 +78,16 @@ discard block |
||
76 | 78 | } |
77 | 79 | |
78 | 80 | public function loadProperties(Hook\PropertyHook $hook) { |
79 | - foreach ($this->properties as $name => $property) $hook->registerProperty($name, $property); |
|
81 | + foreach ($this->properties as $name => $property) { |
|
82 | + $hook->registerProperty($name, $property); |
|
83 | + } |
|
80 | 84 | } |
81 | 85 | |
82 | 86 | public function createPseudoMatcher($pseudo) { |
83 | 87 | $pseudoMatcher = new Hook\PseudoMatcher($pseudo, $this->valueParser); |
84 | - foreach ($this->pseudo as $pseudoFunction) $pseudoMatcher->registerFunction(clone $pseudoFunction); |
|
88 | + foreach ($this->pseudo as $pseudoFunction) { |
|
89 | + $pseudoMatcher->registerFunction(clone $pseudoFunction); |
|
90 | + } |
|
85 | 91 | return $pseudoMatcher; |
86 | 92 | } |
87 | 93 |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | } |
41 | 41 | |
42 | 42 | public function &getLine() { |
43 | - $line = &$this->line; |
|
43 | + $line = &$this->line; |
|
44 | 44 | return $line; |
45 | 45 | } |
46 | 46 | |
@@ -68,9 +68,9 @@ discard block |
||
68 | 68 | $this->properties[$name] = $property; |
69 | 69 | } |
70 | 70 | |
71 | - public function registerContentPseudo($name, Property\ContentPseudo $pseudo) { |
|
72 | - if (isset($this->properties['content'])) $this->properties['content']->addContentPseudo($name, $pseudo); |
|
73 | - } |
|
71 | + public function registerContentPseudo($name, Property\ContentPseudo $pseudo) { |
|
72 | + if (isset($this->properties['content'])) $this->properties['content']->addContentPseudo($name, $pseudo); |
|
73 | + } |
|
74 | 74 | |
75 | 75 | public function registerPseudo(Pseudo $pseudo) { |
76 | 76 | $this->pseudo[] = $pseudo; |
@@ -13,6 +13,9 @@ |
||
13 | 13 | private $functionSet; |
14 | 14 | private $id; |
15 | 15 | |
16 | + /** |
|
17 | + * @param string $id |
|
18 | + */ |
|
16 | 19 | public function __construct(\Transphporm\FunctionSet $functionSet, $prefix = '', $id = null) { |
17 | 20 | $this->id = $id; |
18 | 21 | self::$instances[$this->id] = $this; |
@@ -70,7 +70,9 @@ discard block |
||
70 | 70 | $selector->type = $token['type']; |
71 | 71 | $selectors[] = $selector; |
72 | 72 | } |
73 | - if (isset($token['value'])) $selectors[count($selectors)-1]->string = $token['value']; |
|
73 | + if (isset($token['value'])) { |
|
74 | + $selectors[count($selectors)-1]->string = $token['value']; |
|
75 | + } |
|
74 | 76 | } |
75 | 77 | return $selectors; |
76 | 78 | } |
@@ -80,7 +82,9 @@ discard block |
||
80 | 82 | $selectors = $this->split($css); |
81 | 83 | $xpath = '/'; |
82 | 84 | foreach ($selectors as $selector) { |
83 | - if (isset($this->translators[$selector->type])) $xpath .= $this->translators[$selector->type]($selector->string, $xpath); |
|
85 | + if (isset($this->translators[$selector->type])) { |
|
86 | + $xpath .= $this->translators[$selector->type]($selector->string, $xpath); |
|
87 | + } |
|
84 | 88 | } |
85 | 89 | |
86 | 90 | $xpath = str_replace('/[', '/*[', $xpath); |
@@ -92,11 +96,15 @@ discard block |
||
92 | 96 | $tokens = new Tokens; |
93 | 97 | $split = $css->splitOnToken(Tokenizer::GREATER_THAN); |
94 | 98 | |
95 | - if (count($split) <= 1) return $css; |
|
99 | + if (count($split) <= 1) { |
|
100 | + return $css; |
|
101 | + } |
|
96 | 102 | |
97 | 103 | for ($i = 0; $i < count($split); $i++) { |
98 | 104 | $tokens->add($split[$i]->trim()); |
99 | - if (isset($split[$i+1])) $tokens->add(['type' => Tokenizer::GREATER_THAN]); |
|
105 | + if (isset($split[$i+1])) { |
|
106 | + $tokens->add(['type' => Tokenizer::GREATER_THAN]); |
|
107 | + } |
|
100 | 108 | } |
101 | 109 | |
102 | 110 | return $tokens; |
@@ -19,13 +19,13 @@ discard block |
||
19 | 19 | $this->functionSet = $functionSet; |
20 | 20 | |
21 | 21 | $this->translators = [ |
22 | - Tokenizer::WHITESPACE => function($string) use ($prefix) { return '//' . $prefix . $string; }, |
|
23 | - Tokenizer::MULTIPLY => function () { return '*'; }, |
|
24 | - '' => function($string) use ($prefix) { return '/' . $prefix . $string; }, |
|
25 | - Tokenizer::GREATER_THAN => function($string) use ($prefix) { return '/' . $prefix . $string; }, |
|
26 | - Tokenizer::NUM_SIGN => function($string) { return '[@id=\'' . $string . '\']'; }, |
|
27 | - Tokenizer::DOT => function($string) { return '[contains(concat(\' \', normalize-space(@class), \' \'), \' ' . $string . ' \')]'; }, |
|
28 | - Tokenizer::OPEN_SQUARE_BRACKET => function($string) { return '[' .'php:function(\'\Transphporm\Parser\CssToXpath::processAttr\', \'' . base64_encode(serialize($string)) . '\', ., "' . $this->id . '")' . ']'; } |
|
22 | + Tokenizer::WHITESPACE => function($string) use ($prefix) { return '//'.$prefix.$string; }, |
|
23 | + Tokenizer::MULTIPLY => function() { return '*'; }, |
|
24 | + '' => function($string) use ($prefix) { return '/'.$prefix.$string; }, |
|
25 | + Tokenizer::GREATER_THAN => function($string) use ($prefix) { return '/'.$prefix.$string; }, |
|
26 | + Tokenizer::NUM_SIGN => function($string) { return '[@id=\''.$string.'\']'; }, |
|
27 | + Tokenizer::DOT => function($string) { return '[contains(concat(\' \', normalize-space(@class), \' \'), \' '.$string.' \')]'; }, |
|
28 | + Tokenizer::OPEN_SQUARE_BRACKET => function($string) { return '['.'php:function(\'\Transphporm\Parser\CssToXpath::processAttr\', \''.base64_encode(serialize($string)).'\', ., "'.$this->id.'")'.']'; } |
|
29 | 29 | ]; |
30 | 30 | } |
31 | 31 | |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | $functionSet->setElement($element[0]); |
45 | 45 | |
46 | 46 | $attributes = []; |
47 | - foreach($element[0]->attributes as $name => $node) { |
|
47 | + foreach ($element[0]->attributes as $name => $node) { |
|
48 | 48 | $attributes[$name] = $node->nodeValue; |
49 | 49 | } |
50 | 50 |
@@ -87,7 +87,7 @@ |
||
87 | 87 | if ($token['type'] === $tokenType) $i++; |
88 | 88 | else $splitTokens[$i][] = $token; |
89 | 89 | } |
90 | - return array_map(function ($tokens) { |
|
90 | + return array_map(function($tokens) { |
|
91 | 91 | return new Tokens($tokens); |
92 | 92 | }, $splitTokens); |
93 | 93 | //return $splitTokens; |
@@ -39,8 +39,11 @@ discard block |
||
39 | 39 | } |
40 | 40 | |
41 | 41 | public function add($token) { |
42 | - if ($token instanceof Tokens) $this->tokens = array_merge($token->tokens); |
|
43 | - else $this->tokens[] = $token; |
|
42 | + if ($token instanceof Tokens) { |
|
43 | + $this->tokens = array_merge($token->tokens); |
|
44 | + } else { |
|
45 | + $this->tokens[] = $token; |
|
46 | + } |
|
44 | 47 | } |
45 | 48 | |
46 | 49 | |
@@ -54,9 +57,13 @@ discard block |
||
54 | 57 | |
55 | 58 | private function getKeyToSlice($tokenType) { |
56 | 59 | $keys = $this->getKeysOfTokenType($tokenType); |
57 | - if (empty($keys)) return false; |
|
60 | + if (empty($keys)) { |
|
61 | + return false; |
|
62 | + } |
|
58 | 63 | $key = $keys[0]; |
59 | - for ($i = 0; $key < $this->iterator && isset($keys[$i]); $i++) $key = $keys[$i]; |
|
64 | + for ($i = 0; $key < $this->iterator && isset($keys[$i]); $i++) { |
|
65 | + $key = $keys[$i]; |
|
66 | + } |
|
60 | 67 | return $key; |
61 | 68 | } |
62 | 69 | |
@@ -70,10 +77,17 @@ discard block |
||
70 | 77 | |
71 | 78 | private function sliceTokens($tokenType, $type, $increment = false) { |
72 | 79 | $key = $this->getKeyToSlice($tokenType); |
73 | - if ($key === false) return new Tokens([]); |
|
74 | - if ($increment) $key++; |
|
75 | - if ($type === "from") return new Tokens(array_slice($this->tokens, $key)); |
|
76 | - else return new Tokens(array_slice($this->tokens, $this->iterator, $key)); |
|
80 | + if ($key === false) { |
|
81 | + return new Tokens([]); |
|
82 | + } |
|
83 | + if ($increment) { |
|
84 | + $key++; |
|
85 | + } |
|
86 | + if ($type === "from") { |
|
87 | + return new Tokens(array_slice($this->tokens, $key)); |
|
88 | + } else { |
|
89 | + return new Tokens(array_slice($this->tokens, $this->iterator, $key)); |
|
90 | + } |
|
77 | 91 | } |
78 | 92 | |
79 | 93 | public function skip($count) { |
@@ -84,8 +98,11 @@ discard block |
||
84 | 98 | $splitTokens = []; |
85 | 99 | $i = 0; |
86 | 100 | foreach ($this->tokens as $token) { |
87 | - if ($token['type'] === $tokenType) $i++; |
|
88 | - else $splitTokens[$i][] = $token; |
|
101 | + if ($token['type'] === $tokenType) { |
|
102 | + $i++; |
|
103 | + } else { |
|
104 | + $splitTokens[$i][] = $token; |
|
105 | + } |
|
89 | 106 | } |
90 | 107 | return array_map(function ($tokens) { |
91 | 108 | return new Tokens($tokens); |
@@ -109,7 +126,9 @@ discard block |
||
109 | 126 | |
110 | 127 | public function removeLine() { |
111 | 128 | $tokens = $this->tokens; |
112 | - foreach ($tokens as &$token) unset($token['line']); |
|
129 | + foreach ($tokens as &$token) { |
|
130 | + unset($token['line']); |
|
131 | + } |
|
113 | 132 | return new Tokens($tokens); |
114 | 133 | } |
115 | 134 |