| 1 | <?php |
||
| 11 | class CpuPerformance implements CheckInterface |
||
| 12 | { |
||
| 13 | /** |
||
| 14 | * @var CheckInterface |
||
| 15 | */ |
||
| 16 | private $check; |
||
| 17 | |||
| 18 | public function __construct(array $config = []) |
||
| 29 | |||
| 30 | public function check(): ResultInterface |
||
| 34 | |||
| 35 | public function getLabel(): string |
||
| 39 | |||
| 40 | public function setLabel(string $label): void |
||
| 44 | } |
||
| 45 |
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: