1 | <?php |
||
10 | class ShellBot extends Application |
||
11 | { |
||
12 | private $bot; |
||
13 | |||
14 | /** |
||
15 | * {@inheritdoc} |
||
16 | * |
||
17 | * @param BotCommand $botCommand The BotCommand that executes for this ShellBot. |
||
18 | */ |
||
19 | 2 | public function __construct($name = 'phlackbot', $version = 'UNKNOWN', BotCommand $botCommand = null) |
|
20 | { |
||
21 | 2 | $this->bot = $botCommand ?: new BotCommand(new ConsoleAdapter(new Mainframe())); |
|
22 | 2 | parent::__construct($name, $version); |
|
23 | 2 | } |
|
24 | |||
25 | /** |
||
26 | * Overrides commandName for this ShellBot. |
||
27 | * {@inheritdoc} |
||
28 | */ |
||
29 | protected function getCommandName(InputInterface $input) |
||
33 | |||
34 | /** |
||
35 | * Adds BotCommand as the sole command for this ShellBot. |
||
36 | * {@inheritdoc} |
||
37 | */ |
||
38 | 2 | protected function getDefaultCommands() |
|
45 | |||
46 | /** |
||
47 | * Replaces the default InputDefinition with one containing only the 'command' argument. |
||
48 | * {@inheritdoc} |
||
49 | */ |
||
50 | 1 | public function getDefinition() |
|
59 | } |
||
60 |
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.
Let’s take a look at an example:
Our function
my_function
expects aPost
object, and outputs the author of the post. The base classPost
returns a simple string and outputting a simple string will work just fine. However, the child classBlogPost
which is a sub-type ofPost
instead decided to return anobject
, and is therefore violating the SOLID principles. If aBlogPost
were passed tomy_function
, PHP would not complain, but ultimately fail when executing thestrtoupper
call in its body.