1 | <?php namespace Tequilarapido\Cli\Commands\Base; |
||
6 | abstract class AbstractDatabaseCommand extends AbstractConfigurableCommand |
||
7 | { |
||
8 | |||
9 | protected $databaseName; |
||
10 | protected $databasePrefix; |
||
11 | |||
12 | /** |
||
13 | * Database size (before and after) used in outputGain |
||
14 | * @var array |
||
15 | */ |
||
16 | protected $databaseSize = array(); |
||
17 | |||
18 | /** |
||
19 | * @var Database |
||
20 | */ |
||
21 | protected $db; |
||
22 | |||
23 | /** |
||
24 | * @var Table |
||
25 | */ |
||
26 | protected $table; |
||
27 | |||
28 | protected function setup() |
||
41 | |||
42 | protected function outputGain() |
||
49 | |||
50 | } |
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: