@@ -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,11 @@ discard block |
||
54 | 65 | return $rules; |
55 | 66 | } |
56 | 67 | |
68 | + /** |
|
69 | + * @param integer $pos |
|
70 | + * @param integer $next |
|
71 | + * @param integer $indexStart |
|
72 | + */ |
|
57 | 73 | private function processingInstructions($tss, $pos, $next, $indexStart) { |
58 | 74 | $rules = []; |
59 | 75 | while (($atPos = strpos($tss, '@', $pos)) !== false) { |
@@ -94,6 +110,9 @@ discard block |
||
94 | 110 | return $str; |
95 | 111 | } |
96 | 112 | |
113 | + /** |
|
114 | + * @param string $str |
|
115 | + */ |
|
97 | 116 | private function getProperties($str) { |
98 | 117 | $stringExtractor = new StringExtractor($str); |
99 | 118 | $rules = explode(';', $stringExtractor); |
@@ -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), count($rules)+$indexStart)) $rules = array_merge($rules, $processing['rules']); |
|
36 | + if ($processing = $this->processingInstructions($this->tss, $pos, strlen($this->tss), count($rules)+$indexStart)) { |
|
37 | + $rules = array_merge($rules, $processing['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, $indexStart)); |
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]); |