1 | <?php namespace Tequilarapido\Cli\Commands\Base; |
||
9 | abstract class AbstractCommand extends Command |
||
10 | { |
||
11 | protected $startTime; |
||
12 | protected $progress; |
||
13 | |||
14 | /** |
||
15 | * @var InputInterface |
||
16 | */ |
||
17 | protected $input; |
||
18 | |||
19 | |||
20 | /** |
||
21 | * @var OutputInterface |
||
22 | * We need it public, as it is used inside a closure in AbstractCommand::elapsed method |
||
23 | */ |
||
24 | public $output; |
||
25 | |||
26 | |||
27 | public function __construct($name = null) |
||
31 | |||
32 | protected function execute(InputInterface $input, OutputInterface $output) |
||
38 | |||
39 | public function table($data) |
||
49 | |||
50 | |||
51 | // |
||
52 | // Time / Benchmarking stuff |
||
53 | // |
||
54 | protected function elapsed() |
||
72 | |||
73 | public function getStartTime() |
||
77 | |||
78 | protected function iAmHungry($memory_limit = '1024M') |
||
83 | |||
84 | |||
85 | } |
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 sub-classes 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 parent class: