Conditions | 7 |
Paths | 6 |
Total Lines | 30 |
Code Lines | 14 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 56 |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
1 | <?php |
||
22 | public function validate(Configuration $configuration) |
||
23 | { |
||
24 | parent::validate($configuration); |
||
|
|||
25 | |||
26 | // If not valid, then we are done. |
||
27 | if (!$this->isValid) { |
||
28 | return; |
||
29 | } |
||
30 | |||
31 | // If no cleaning, then we are done. |
||
32 | if ($configuration->get('clean-strategy') == 'none') { |
||
33 | return; |
||
34 | } |
||
35 | |||
36 | // "base" must be child of "head". |
||
37 | if ($this->getParent() === null || $this->getParent()->getName() !== 'head') { |
||
38 | $this->handleValidationError( |
||
39 | $configuration, |
||
40 | 'Base element must be a child of a "head" element.' |
||
41 | ); |
||
42 | } |
||
43 | |||
44 | // Must have either "href" or "target" attribute or both. |
||
45 | if (!$this->hasAttribute('href') && !$this->hasAttribute('target')) { |
||
46 | $this->handleValidationError( |
||
47 | $configuration, |
||
48 | 'Base element must have either "href" or "target" attribute or both.' |
||
49 | ); |
||
50 | } |
||
51 | } |
||
52 | } |
||
53 |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the parent class: