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 | protected function extractSelector(array &$selectors, $rule) |
||
125 | |||
126 | /** |
||
127 | * Set the stylesheet reader instance |
||
128 | * |
||
129 | * @param \Crossjoin\Css\Reader\CssString|string $stylesheet |
||
130 | * @return $this |
||
131 | * |
||
132 | * @throws \InvalidArgumentException |
||
133 | */ |
||
134 | public function setStylesheetReader($stylesheet) |
||
151 | |||
152 | /** |
||
153 | * Get the stylesheet reader instance |
||
154 | * |
||
155 | * @return \Crossjoin\Css\Reader\CssString|null |
||
156 | */ |
||
157 | public function getStylesheetReader() |
||
161 | |||
162 | /** |
||
163 | * Set the charset of the stylesheet |
||
164 | * |
||
165 | * @param string $charset |
||
166 | * @return $this |
||
167 | */ |
||
168 | public function setCharset($charset) |
||
174 | |||
175 | /** |
||
176 | * Get the charset of the stylesheet |
||
177 | * |
||
178 | * @return string |
||
179 | */ |
||
180 | public function getCharset() |
||
184 | |||
185 | /** |
||
186 | * Check if a Selector has a valid Pseudo Class |
||
187 | * |
||
188 | * @param \Crossjoin\Css\Format\Rule\Style\StyleSelector $selector |
||
189 | * @return bool |
||
190 | */ |
||
191 | public function isPseudoClassAllowed(StyleSelector $selector) |
||
203 | |||
204 | /** |
||
205 | * Gets all generally relevant style rules |
||
206 | * |
||
207 | * @param RuleAbstract[] $rules |
||
208 | * @return StyleRuleSet[] |
||
209 | */ |
||
210 | protected function getRelevantStyleRules(array $rules) |
||
229 | |||
230 | /** |
||
231 | * Gets the relevant style rules from a media rule |
||
232 | * |
||
233 | * @param \Crossjoin\Css\Format\Rule\AtMedia\MediaRule $rule |
||
234 | * @param array &$collection |
||
235 | * @return void |
||
236 | */ |
||
237 | protected function getRelevantMediaRule(MediaRule $rule, &$collection) |
||
254 | |||
255 | protected function isAllowedMediaRule($media_query) |
||
262 | |||
263 | } |
||
264 |
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.