| 1 | <?php |
||
| 8 | class CronService |
||
| 9 | { |
||
| 10 | /** |
||
| 11 | * @var integer |
||
| 12 | */ |
||
| 13 | protected $timeout = null; |
||
| 14 | |||
| 15 | /** |
||
| 16 | * @var Cron |
||
| 17 | */ |
||
| 18 | protected $cron = null; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * @var int |
||
| 22 | */ |
||
| 23 | protected $startTime = null; |
||
| 24 | |||
| 25 | public function __construct($timeout, Cron $cron) |
||
| 30 | |||
| 31 | public function run() |
||
| 39 | |||
| 40 | protected function wait() |
||
| 46 | |||
| 47 | protected function checkTimeout() |
||
| 59 | |||
| 60 | protected function throwErrorIfTimeout() |
||
| 66 | |||
| 67 | protected function assembleErrorString() |
||
| 78 | } |
||
| 79 |
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: