| Conditions | 7 |
| Paths | 13 |
| Total Lines | 26 |
| Code Lines | 15 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 20 |
| CRAP Score | 7 |
| Changes | 0 | ||
| 1 | <?php |
||
| 42 | 2 | private function resetHandler(HandlerInterface $handler) |
|
| 43 | { |
||
| 44 | 2 | $class = get_class($handler); |
|
| 45 | |||
| 46 | 2 | $prefix = 'Monolog\\Handler\\'; |
|
| 47 | |||
| 48 | 2 | if (substr($class, 0, strlen($prefix)) == $prefix) { |
|
| 49 | 2 | $handlerName = substr($class, strlen($prefix)); |
|
| 50 | |||
| 51 | 2 | if ('FingersCrossedHandler' == $handlerName) { |
|
| 52 | 1 | $handler->clear(); |
|
|
|
|||
| 53 | 2 | } elseif ('BufferHandler' == $handlerName || 'StreamHandler' == $handlerName) { |
|
| 54 | 1 | $handler->close(); |
|
| 55 | 1 | } |
|
| 56 | |||
| 57 | 2 | if (property_exists($handler, 'handler')) { |
|
| 58 | 2 | $subHandler = Util::readProperty($handler, 'handler'); |
|
| 59 | 2 | $this->resetHandler($subHandler); |
|
| 60 | 2 | } |
|
| 61 | |||
| 62 | 2 | if (property_exists($handler, 'handlers')) { |
|
| 63 | 1 | $subHandlers = Util::readProperty($handler, 'handlers'); |
|
| 64 | 1 | $this->resetHandlers($subHandlers); |
|
| 65 | 1 | } |
|
| 66 | 2 | } |
|
| 67 | 2 | } |
|
| 68 | } |
||
| 69 |
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: