| 1 | <?php declare(strict_types=1); |
||
| 10 | class Build extends BaseBuild |
||
| 11 | { |
||
| 12 | /** |
||
| 13 | * @return array |
||
| 14 | */ |
||
| 15 | public function jobs(): array |
||
| 25 | |||
| 26 | /** |
||
| 27 | * @param int $id |
||
| 28 | * @return Job |
||
| 29 | */ |
||
| 30 | public function job(int $id): Job |
||
| 40 | |||
| 41 | /** |
||
| 42 | * @return Build |
||
| 43 | */ |
||
| 44 | public function refresh(): Build |
||
| 54 | } |
||
| 55 |
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: