1 | <?php namespace Luminaire\Premailer\Parser; |
||
26 | class RelevantSelectorParser |
||
27 | { |
||
28 | |||
29 | /** |
||
30 | * The pseudo classes that can be set in a style attribute and that are |
||
31 | * supported by the Symfony CssSelector (doesn't support CSS4 yet). |
||
32 | * |
||
33 | * @var array |
||
34 | */ |
||
35 | protected $allowed_pseudo_classes = [ |
||
36 | StyleSelector::PSEUDO_CLASS_FIRST_CHILD, |
||
37 | StyleSelector::PSEUDO_CLASS_ROOT, |
||
38 | StyleSelector::PSEUDO_CLASS_NTH_CHILD, |
||
39 | StyleSelector::PSEUDO_CLASS_NTH_LAST_CHILD, |
||
40 | StyleSelector::PSEUDO_CLASS_NTH_OF_TYPE, |
||
41 | StyleSelector::PSEUDO_CLASS_NTH_LAST_OF_TYPE, |
||
42 | StyleSelector::PSEUDO_CLASS_LAST_CHILD, |
||
43 | StyleSelector::PSEUDO_CLASS_FIRST_OF_TYPE, |
||
44 | StyleSelector::PSEUDO_CLASS_LAST_OF_TYPE, |
||
45 | StyleSelector::PSEUDO_CLASS_ONLY_CHILD, |
||
46 | StyleSelector::PSEUDO_CLASS_ONLY_OF_TYPE, |
||
47 | StyleSelector::PSEUDO_CLASS_EMPTY, |
||
48 | StyleSelector::PSEUDO_CLASS_NOT, |
||
49 | ]; |
||
50 | |||
51 | /** |
||
52 | * The stylesheet reader instance |
||
53 | * |
||
54 | * @var \Crossjoin\Css\Reader\CssString |
||
55 | */ |
||
56 | protected $stylesheet; |
||
57 | |||
58 | /** |
||
59 | * The charset of the stylesheet |
||
60 | * |
||
61 | * @var string |
||
62 | */ |
||
63 | protected $charset; |
||
64 | |||
65 | /** |
||
66 | * Create a new instance of "Relevant Selector Parser" |
||
67 | * |
||
68 | * @param \Crossjoin\Css\Reader\CssString|string|null $stylesheet |
||
69 | * @param string $charset |
||
70 | */ |
||
71 | public function __construct($stylesheet = null, $charset = 'UTF-8') |
||
80 | |||
81 | /** |
||
82 | * Get the relevant selectors |
||
83 | * |
||
84 | * @param \Crossjoin\Css\Reader\CssString $reader |
||
|
|||
85 | * @return array |
||
86 | */ |
||
87 | public function extract() |
||
100 | |||
101 | /** |
||
102 | * Store the selectors from the rule to the tank |
||
103 | * |
||
104 | * @param array &$tank |
||
105 | * @param array $selectors |
||
106 | * @return void |
||
107 | */ |
||
108 | protected function populateSelectors(array &$tank, $rule) |
||
129 | |||
130 | protected function storeDeclaration(array &$tank, $declaration) |
||
134 | |||
135 | /** |
||
136 | * Before building the dictionary of declaration we will need to make sure |
||
137 | * there are an empty array. |
||
138 | * |
||
139 | * @param array &$selectors |
||
140 | * @param string $specifity |
||
141 | * @param string $name |
||
142 | * @return void |
||
143 | */ |
||
144 | protected function prepareSelectorArray(array &$selectors, $specifity, $name) |
||
158 | |||
159 | /** |
||
160 | * Set the stylesheet reader instance |
||
161 | * |
||
162 | * @param \Crossjoin\Css\Reader\CssString|string $stylesheet |
||
163 | * @return $this |
||
164 | * |
||
165 | * @throws \InvalidArgumentException |
||
166 | */ |
||
167 | public function setStylesheetReader($stylesheet) |
||
184 | |||
185 | /** |
||
186 | * Get the stylesheet reader instance |
||
187 | * |
||
188 | * @return \Crossjoin\Css\Reader\CssString|null |
||
189 | */ |
||
190 | public function getStylesheetReader() |
||
194 | |||
195 | /** |
||
196 | * Set the charset of the stylesheet |
||
197 | * |
||
198 | * @param string $charset |
||
199 | * @return $this |
||
200 | */ |
||
201 | public function setCharset($charset) |
||
207 | |||
208 | /** |
||
209 | * Get the charset of the stylesheet |
||
210 | * |
||
211 | * @return string |
||
212 | */ |
||
213 | public function getCharset() |
||
217 | |||
218 | /** |
||
219 | * Check if a Selector has a valid Pseudo Class |
||
220 | * |
||
221 | * @param \Crossjoin\Css\Format\Rule\Style\StyleSelector $selector |
||
222 | * @return bool |
||
223 | */ |
||
224 | public function isPseudoClassAllowed(StyleSelector $selector) |
||
236 | |||
237 | /** |
||
238 | * Gets all generally relevant style rules |
||
239 | * |
||
240 | * @param RuleAbstract[] $rules |
||
241 | * @return StyleRuleSet[] |
||
242 | */ |
||
243 | protected function getRelevantStyleRules(array $rules) |
||
262 | |||
263 | /** |
||
264 | * Gets the relevant style rules from a media rule |
||
265 | * |
||
266 | * @param \Crossjoin\Css\Format\Rule\AtMedia\MediaRule $rule |
||
267 | * @param array &$collection |
||
268 | * @return void |
||
269 | */ |
||
270 | protected function getRelevantMediaRule(MediaRule $rule, &$collection) |
||
287 | |||
288 | protected function isAllowedMediaRule($media_query) |
||
295 | |||
296 | } |
||
297 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.