Conditions | 7 |
Paths | 5 |
Total Lines | 22 |
Code Lines | 10 |
Lines | 7 |
Ratio | 31.82 % |
Tests | 4 |
CRAP Score | 21.5206 |
Changes | 2 | ||
Bugs | 0 | Features | 1 |
1 | <?php |
||
28 | 1 | protected function doClean(LoggerInterface $logger = null) |
|
29 | { |
||
30 | // "base" element must be child of "head" element. |
||
31 | 1 | if ($this->getParent() !== null && $this->getParent()->getName() !== 'head') { |
|
|
|||
32 | if ($logger !== null) { |
||
33 | $logger->debug('Element "base" must be a "head" element child.'); |
||
34 | } |
||
35 | |||
36 | return false; |
||
37 | } |
||
38 | |||
39 | // Must have either "href" or "target" attribute or both. |
||
40 | 1 | View Code Duplication | if (!$this->hasAttribute('href') && !$this->hasAttribute('target')) { |
41 | if ($logger !== null) { |
||
42 | $logger->debug('Element "base" must have either the "href" or "target" attribute or both.'); |
||
43 | } |
||
44 | |||
45 | return false; |
||
46 | } |
||
47 | |||
48 | 1 | return true; |
|
49 | } |
||
50 | } |
||
51 |
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 implementation 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 interface: