1 | <?php |
||
13 | class CommandManager extends Manager |
||
14 | { |
||
15 | /** @var string */ |
||
16 | protected $name; |
||
17 | |||
18 | public function __construct($command = '') |
||
26 | |||
27 | /** |
||
28 | * Set the name of this command |
||
29 | * @param string $name |
||
30 | */ |
||
31 | public function command($name) |
||
35 | |||
36 | public function getCommand() |
||
40 | |||
41 | /** |
||
42 | * Add an argument. |
||
43 | * |
||
44 | * @throws \Exception if $argument isn't an array or Argument object. |
||
45 | * @param Argument|string|array $argument |
||
46 | * @param $options |
||
47 | */ |
||
48 | public function add($argument, array $options = []) |
||
65 | |||
66 | /** |
||
67 | * Output a script's usage statement. |
||
68 | * |
||
69 | * @param CLImate $climate |
||
70 | * @param array $argv |
||
71 | */ |
||
72 | public function usage(CLImate $climate, array $argv = null) |
||
81 | |||
82 | /** |
||
83 | * Get a script's short statement. |
||
84 | */ |
||
85 | public function shortUsage() |
||
93 | } |
||
94 |
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: