@@ -39,6 +39,9 @@ discard block |
||
39 | 39 | return $this->properties; |
40 | 40 | } |
41 | 41 | |
42 | + /** |
|
43 | + * @param \DOMElement $element |
|
44 | + */ |
|
42 | 45 | private function callProperty($name, $element, $value) { |
43 | 46 | foreach ($this->properties as $obj) { |
44 | 47 | if (is_callable([$obj, $name])) { |
@@ -117,6 +120,9 @@ discard block |
||
117 | 120 | return false; |
118 | 121 | } |
119 | 122 | |
123 | + /** |
|
124 | + * @param string $remaining |
|
125 | + */ |
|
120 | 126 | private function parseNextValue($remaining, $result, $element) { |
121 | 127 | if (strlen($remaining) > 0 && $remaining[0] == ',') $result = array_merge($result, $this->parseValue(trim(substr($remaining, 1)), $element)); |
122 | 128 | 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) { |
@@ -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 |
@@ -7,14 +7,14 @@ |
||
7 | 7 | private $depth; |
8 | 8 | |
9 | 9 | public function __construct($css, $prefix = '') { |
10 | - $this->css = str_replace([' >', '> '],['>', '>'], trim($css)); |
|
10 | + $this->css = str_replace([' >', '> '], ['>', '>'], trim($css)); |
|
11 | 11 | $this->translators = [ |
12 | - ' ' => function($string) use ($prefix) { return '//' . $prefix . $string; }, |
|
13 | - '' => function($string) use ($prefix) { return '/' . $prefix . $string; }, |
|
14 | - '>' => function($string) use ($prefix) { return '/' . $prefix . $string; }, |
|
15 | - '#' => function($string) { return '[@id=\'' . $string . '\']'; }, |
|
16 | - '.' => function($string) { return '[contains(concat(\' \', normalize-space(@class), \' \'), \' ' . $string . ' \')]'; }, |
|
17 | - '[' => function($string) { return '[@' . $string . ']'; }, |
|
12 | + ' ' => function($string) use ($prefix) { return '//'.$prefix.$string; }, |
|
13 | + '' => function($string) use ($prefix) { return '/'.$prefix.$string; }, |
|
14 | + '>' => function($string) use ($prefix) { return '/'.$prefix.$string; }, |
|
15 | + '#' => function($string) { return '[@id=\''.$string.'\']'; }, |
|
16 | + '.' => function($string) { return '[contains(concat(\' \', normalize-space(@class), \' \'), \' '.$string.' \')]'; }, |
|
17 | + '[' => function($string) { return '[@'.$string.']'; }, |
|
18 | 18 | ']' => function() { return ''; } |
19 | 19 | ]; |
20 | 20 | } |
@@ -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); |
@@ -11,7 +11,7 @@ discard block |
||
11 | 11 | /** Converts $val into a \DateTime object if it's not already */ |
12 | 12 | private function getDate($val) { |
13 | 13 | $tz = new \DateTimeZone($this->locale['timezone']); |
14 | - $date = $val instanceof \DateTime ? $val : new \DateTime($val, $tz); |
|
14 | + $date = $val instanceof \DateTime ? $val : new \DateTime($val, $tz); |
|
15 | 15 | $date->setTimeZone($tz); |
16 | 16 | return $date; |
17 | 17 | } |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | |
31 | 31 | /** Formats \DateTime as Date and Time using formats from $locale */ |
32 | 32 | public function dateTime($val) { |
33 | - return $this->date($val, $this->locale['date_format'] . ' ' . $this->locale['time_format']); |
|
33 | + return $this->date($val, $this->locale['date_format'].' '.$this->locale['time_format']); |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | /** Generates relative time offsets based on system clock. e.g "10 minutes ago" or "In 6 months" |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | $diff = $now->diff($date); |
43 | 43 | |
44 | 44 | |
45 | - $diffDays = $diff->invert === 1 ? $diff->days : 0- $diff->days; |
|
45 | + $diffDays = $diff->invert === 1 ? $diff->days : 0-$diff->days; |
|
46 | 46 | |
47 | 47 | if ($diffDays !== 0) return $this->dayOffset($diffDays); |
48 | 48 | else return $this->timeOffset($diff); |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | |
69 | 69 | /** Gets date ranges to represent uses of weeks/months/days/etc */ |
70 | 70 | private function getRanges($strings) { |
71 | - $ranges = [ |
|
71 | + $ranges = [ |
|
72 | 72 | [1, 1, $strings['yesterday'], 1, ''], |
73 | 73 | [1, 13, $strings['past'], 1, 'days'], |
74 | 74 | [13, 28, $strings['past'], 7, 'weeks'], |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | |
88 | 88 | /** Converts "week" to "weeks", "month" to "months" etc when plural is required using language from $locale */ |
89 | 89 | private function getPlural($strings, $num, $interval) { |
90 | - if ($interval !== '') return $num == 1 ? $strings[$interval . '_singular'] : $strings[$interval . '_plural']; |
|
90 | + if ($interval !== '') return $num == 1 ? $strings[$interval.'_singular'] : $strings[$interval.'_plural']; |
|
91 | 91 | else return ''; |
92 | 92 | } |
93 | 93 |
@@ -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,7 @@ |
||
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') return $this->locale['currency'].$num; |
|
17 | + else return $num.$this->locale['currency']; |
|
18 | 18 | } |
19 | 19 | } |
20 | 20 | \ No newline at end of file |
@@ -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 |
@@ -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 | } |
@@ -22,8 +22,11 @@ discard block |
||
22 | 22 | //Remove the current contents |
23 | 23 | $this->removeAllChildren($element); |
24 | 24 | //Now make a text node |
25 | - if ($this->getContentMode($rule->getRules()) === 'replace') $this->replaceContent($element, $value); |
|
26 | - else $this->appendContent($element, $value); |
|
25 | + if ($this->getContentMode($rule->getRules()) === 'replace') { |
|
26 | + $this->replaceContent($element, $value); |
|
27 | + } else { |
|
28 | + $this->appendContent($element, $value); |
|
29 | + } |
|
27 | 30 | } |
28 | 31 | } |
29 | 32 | |
@@ -88,17 +91,23 @@ discard block |
||
88 | 91 | } |
89 | 92 | |
90 | 93 | private function removeAllChildren($element) { |
91 | - while ($element->hasChildNodes()) $element->removeChild($element->firstChild); |
|
94 | + while ($element->hasChildNodes()) { |
|
95 | + $element->removeChild($element->firstChild); |
|
96 | + } |
|
92 | 97 | } |
93 | 98 | |
94 | 99 | private function createHook($newRules, $rule) { |
95 | 100 | $hook = new Rule($newRules, $rule->getPseudoMatcher(), $this->data); |
96 | - foreach ($rule->getProperties() as $obj) $hook->registerProperties($obj); |
|
101 | + foreach ($rule->getProperties() as $obj) { |
|
102 | + $hook->registerProperties($obj); |
|
103 | + } |
|
97 | 104 | return $hook; |
98 | 105 | } |
99 | 106 | |
100 | 107 | public function repeat($value, $element, $rule) { |
101 | - if ($element->getAttribute('transphporm') === 'added') return $element->parentNode->removeChild($element); |
|
108 | + if ($element->getAttribute('transphporm') === 'added') { |
|
109 | + return $element->parentNode->removeChild($element); |
|
110 | + } |
|
102 | 111 | |
103 | 112 | foreach ($value as $key => $iteration) { |
104 | 113 | $clone = $element->cloneNode(true); |
@@ -121,8 +130,11 @@ discard block |
||
121 | 130 | } |
122 | 131 | |
123 | 132 | public function display($value, $element) { |
124 | - if (strtolower($value[0]) === 'none') $element->setAttribute('transphporm', 'remove'); |
|
125 | - else $element->setAttribute('transphporm', 'show'); |
|
133 | + if (strtolower($value[0]) === 'none') { |
|
134 | + $element->setAttribute('transphporm', 'remove'); |
|
135 | + } else { |
|
136 | + $element->setAttribute('transphporm', 'show'); |
|
137 | + } |
|
126 | 138 | } |
127 | 139 | |
128 | 140 | public function bind($value, $element) { |
@@ -75,7 +75,7 @@ |
||
75 | 75 | } |
76 | 76 | |
77 | 77 | public function template($val, $element) { |
78 | - $newTemplate = new \Transphporm\Builder($this->baseDir . $val[0]); |
|
78 | + $newTemplate = new \Transphporm\Builder($this->baseDir.$val[0]); |
|
79 | 79 | $newTemplate->setLocale($this->locale); |
80 | 80 | |
81 | 81 | $doc = $newTemplate->output([], true)->body; |
@@ -12,6 +12,9 @@ |
||
12 | 12 | private $locale; |
13 | 13 | private $baseDir; |
14 | 14 | |
15 | + /** |
|
16 | + * @param string $baseDir |
|
17 | + */ |
|
15 | 18 | public function __construct(\SplObjectStorage $objectStorage, $data, $locale, $baseDir) { |
16 | 19 | $this->dataStorage = $objectStorage; |
17 | 20 | $this->data = $data; |
@@ -22,7 +22,9 @@ discard block |
||
22 | 22 | /** Binds data to an element */ |
23 | 23 | public function bind(\DomElement $element, $data, $type = '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 | $content = isset($this->dataStorage[$element]) ? $this->dataStorage[$element] : []; |
27 | 29 | $content[$type] = $data; |
28 | 30 | $this->dataStorage[$element] = $content; |
@@ -45,7 +47,9 @@ discard block |
||
45 | 47 | /** 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*/ |
46 | 48 | private function getData(\DomElement $element, $type = 'data') { |
47 | 49 | while ($element) { |
48 | - if (isset($this->dataStorage[$element]) && isset($this->dataStorage[$element][$type])) return $this->dataStorage[$element][$type]; |
|
50 | + if (isset($this->dataStorage[$element]) && isset($this->dataStorage[$element][$type])) { |
|
51 | + return $this->dataStorage[$element][$type]; |
|
52 | + } |
|
49 | 53 | $element = $element->parentNode; |
50 | 54 | } |
51 | 55 | return $this->data; |
@@ -62,16 +66,24 @@ discard block |
||
62 | 66 | $parts = explode('.', $name[0]); |
63 | 67 | $obj = $data; |
64 | 68 | foreach ($parts as $part) { |
65 | - if ($part === '') continue; |
|
66 | - if (is_callable([$obj, $part])) $obj = call_user_func([$obj, $part]); |
|
67 | - else $obj = $this->ifNull($obj, $part); |
|
69 | + if ($part === '') { |
|
70 | + continue; |
|
71 | + } |
|
72 | + if (is_callable([$obj, $part])) { |
|
73 | + $obj = call_user_func([$obj, $part]); |
|
74 | + } else { |
|
75 | + $obj = $this->ifNull($obj, $part); |
|
76 | + } |
|
68 | 77 | } |
69 | 78 | return $obj; |
70 | 79 | } |
71 | 80 | |
72 | 81 | private function ifNull($obj, $key) { |
73 | - if (is_array($obj)) return isset($obj[$key]) ? $obj[$key] : null; |
|
74 | - else return isset($obj->$key) ? $obj->$key : null; |
|
82 | + if (is_array($obj)) { |
|
83 | + return isset($obj[$key]) ? $obj[$key] : null; |
|
84 | + } else { |
|
85 | + return isset($obj->$key) ? $obj->$key : null; |
|
86 | + } |
|
75 | 87 | } |
76 | 88 | |
77 | 89 | public function attr($val, $element) { |
@@ -97,14 +109,18 @@ discard block |
||
97 | 109 | |
98 | 110 | $doc = $newTemplate->output([], true)->body; |
99 | 111 | |
100 | - if (isset($val[1])) return $this->templateSubsection($val[1], $doc, $element); |
|
112 | + if (isset($val[1])) { |
|
113 | + return $this->templateSubsection($val[1], $doc, $element); |
|
114 | + } |
|
101 | 115 | |
102 | 116 | $newNode = $element->ownerDocument->importNode($doc->documentElement, true); |
103 | 117 | |
104 | 118 | $result = []; |
105 | 119 | |
106 | 120 | if ($newNode->tagName === 'template') { |
107 | - foreach ($newNode->childNodes as $node) $result[] = $node->cloneNode(true); |
|
121 | + foreach ($newNode->childNodes as $node) { |
|
122 | + $result[] = $node->cloneNode(true); |
|
123 | + } |
|
108 | 124 | } |
109 | 125 | //else $result[] = $newNode; |
110 | 126 |
@@ -77,7 +77,7 @@ |
||
77 | 77 | return false; |
78 | 78 | } |
79 | 79 | |
80 | - public function header($element) { |
|
80 | + public function header($element) { |
|
81 | 81 | if ($this->matches($element)) { |
82 | 82 | foreach ($this->pseudo as $pseudo) { |
83 | 83 | if (strpos($pseudo, 'header') === 0) return $this->getBetween($pseudo, '[', ']'); |
@@ -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 | } |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | |
22 | 22 | $selector = trim(substr($this->tss, $pos, $next-$pos)); |
23 | 23 | $rule = $this->cssToRule($selector, count($rules)); |
24 | - $pos = strpos($this->tss, '}', $next)+1; |
|
24 | + $pos = strpos($this->tss, '}', $next)+1; |
|
25 | 25 | $rule->properties = $this->getProperties(trim(substr($this->tss, $next+1, $pos-2-$next))); |
26 | 26 | $rules = $this->writeRule($rules, $selector, $rule); |
27 | 27 | } |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | private function processingInstructions($tss, $pos, $next) { |
53 | 53 | $rules = []; |
54 | 54 | while (($atPos = strpos($tss, '@', $pos)) !== false) { |
55 | - if ($atPos <= (int) $next) { |
|
55 | + if ($atPos <= (int) $next) { |
|
56 | 56 | $spacePos = strpos($tss, ' ', $atPos); |
57 | 57 | $funcName = substr($tss, $atPos+1, $spacePos-$atPos-1); |
58 | 58 | $pos = strpos($tss, ';', $spacePos); |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | } |
67 | 67 | |
68 | 68 | private function import($args) { |
69 | - $sheet = new Sheet(file_get_contents($this->baseDir . trim($args, '\'" ')), $this->baseDir); |
|
69 | + $sheet = new Sheet(file_get_contents($this->baseDir.trim($args, '\'" ')), $this->baseDir); |
|
70 | 70 | return $sheet->parse(); |
71 | 71 | } |
72 | 72 |
@@ -11,6 +11,9 @@ discard block |
||
11 | 11 | private $baseDir; |
12 | 12 | private $prefix; |
13 | 13 | |
14 | + /** |
|
15 | + * @param string $tss |
|
16 | + */ |
|
14 | 17 | public function __construct($tss, $baseDir, $prefix = '') { |
15 | 18 | $this->tss = $this->stripComments($tss); |
16 | 19 | $this->baseDir = $baseDir; |
@@ -36,12 +39,20 @@ discard block |
||
36 | 39 | return $rules; |
37 | 40 | } |
38 | 41 | |
42 | + /** |
|
43 | + * @param string $selector |
|
44 | + * @param integer $index |
|
45 | + */ |
|
39 | 46 | private function CssToRule($selector, $index) { |
40 | 47 | $xPath = new CssToXpath($selector, $this->prefix); |
41 | 48 | $rule = new Rule($xPath->getXpath(), $xPath->getPseudo(), $xPath->getDepth(), $index++); |
42 | 49 | return $rule; |
43 | 50 | } |
44 | 51 | |
52 | + /** |
|
53 | + * @param string $selector |
|
54 | + * @param Rule $newRule |
|
55 | + */ |
|
45 | 56 | private function writeRule($rules, $selector, $newRule) { |
46 | 57 | if (isset($rules[$selector])) $newRule->properties = array_merge($rules[$selector], $newRule->properties); |
47 | 58 | $rules[$selector] = $newRule; |
@@ -49,6 +60,10 @@ discard block |
||
49 | 60 | return $rules; |
50 | 61 | } |
51 | 62 | |
63 | + /** |
|
64 | + * @param integer $pos |
|
65 | + * @param integer $next |
|
66 | + */ |
|
52 | 67 | private function processingInstructions($tss, $pos, $next) { |
53 | 68 | $rules = []; |
54 | 69 | while (($atPos = strpos($tss, '@', $pos)) !== false) { |
@@ -87,6 +102,9 @@ discard block |
||
87 | 102 | return $str; |
88 | 103 | } |
89 | 104 | |
105 | + /** |
|
106 | + * @param string $str |
|
107 | + */ |
|
90 | 108 | private function getProperties($str) { |
91 | 109 | $stringExtractor = new \Transphporm\StringExtractor($str); |
92 | 110 | $rules = explode(';', $stringExtractor); |
@@ -31,7 +31,9 @@ discard block |
||
31 | 31 | $rules = $this->writeRule($rules, $selector, $rule); |
32 | 32 | } |
33 | 33 | //there may be processing instructions at the end |
34 | - if ($processing = $this->processingInstructions($this->tss, $pos, strlen($this->tss))) $rules = array_merge($processing['rules'], $rules); |
|
34 | + if ($processing = $this->processingInstructions($this->tss, $pos, strlen($this->tss))) { |
|
35 | + $rules = array_merge($processing['rules'], $rules); |
|
36 | + } |
|
35 | 37 | usort($rules, [$this, 'sortRules']); |
36 | 38 | return $rules; |
37 | 39 | } |
@@ -43,7 +45,9 @@ discard block |
||
43 | 45 | } |
44 | 46 | |
45 | 47 | private function writeRule($rules, $selector, $newRule) { |
46 | - if (isset($rules[$selector])) $newRule->properties = array_merge($rules[$selector], $newRule->properties); |
|
48 | + if (isset($rules[$selector])) { |
|
49 | + $newRule->properties = array_merge($rules[$selector], $newRule->properties); |
|
50 | + } |
|
47 | 51 | $rules[$selector] = $newRule; |
48 | 52 | |
49 | 53 | return $rules; |
@@ -58,8 +62,7 @@ discard block |
||
58 | 62 | $pos = strpos($tss, ';', $spacePos); |
59 | 63 | $args = substr($tss, $spacePos+1, $pos-$spacePos-1); |
60 | 64 | $rules = array_merge($rules, $this->$funcName($args)); |
61 | - } |
|
62 | - else { |
|
65 | + } else { |
|
63 | 66 | break; |
64 | 67 | } |
65 | 68 | } |
@@ -74,7 +77,9 @@ discard block |
||
74 | 77 | |
75 | 78 | private function sortRules($a, $b) { |
76 | 79 | //If they have the same depth, compare on index |
77 | - if ($a->depth === $b->depth) return $a->index < $b->index ? -1 : 1; |
|
80 | + if ($a->depth === $b->depth) { |
|
81 | + return $a->index < $b->index ? -1 : 1; |
|
82 | + } |
|
78 | 83 | |
79 | 84 | return ($a->depth < $b->depth) ? -1 : 1; |
80 | 85 | } |
@@ -95,7 +100,9 @@ discard block |
||
95 | 100 | $return = []; |
96 | 101 | |
97 | 102 | foreach ($rules as $rule) { |
98 | - if (trim($rule) === '') continue; |
|
103 | + if (trim($rule) === '') { |
|
104 | + continue; |
|
105 | + } |
|
99 | 106 | $parts = explode(':', $rule, 2); |
100 | 107 | |
101 | 108 | $parts[1] = $stringExtractor->rebuild($parts[1]); |
@@ -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 | } |