These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * This file is part of the Jira-CLI library. |
||
4 | * For the full copyright and license information, please view |
||
5 | * the LICENSE file that was distributed with this source code. |
||
6 | * |
||
7 | * @copyright Alexander Obuhovich <[email protected]> |
||
8 | * @link https://github.com/console-helpers/jira-cli |
||
9 | */ |
||
10 | |||
11 | namespace ConsoleHelpers\JiraCLI; |
||
12 | |||
13 | |||
14 | use ConsoleHelpers\JiraCLI\Command\BackportCommand; |
||
15 | use ConsoleHelpers\JiraCLI\Command\ChangeLogCloneCommand; |
||
16 | use ConsoleHelpers\JiraCLI\Command\DownloadAttachmentCommand; |
||
17 | use ConsoleHelpers\ConsoleKit\Application as BaseApplication; |
||
18 | use ConsoleHelpers\JiraCLI\Command\VersionsCommand; |
||
19 | use Symfony\Component\Console\Command\Command; |
||
20 | |||
21 | class Application extends BaseApplication |
||
22 | { |
||
23 | |||
24 | /** |
||
25 | * Initializes all the composer commands. |
||
26 | * |
||
27 | * @return Command[] An array of default Command instances. |
||
28 | */ |
||
29 | protected function getDefaultCommands() |
||
30 | { |
||
31 | $default_commands = parent::getDefaultCommands(); |
||
32 | $default_commands[] = new DownloadAttachmentCommand(); |
||
33 | $default_commands[] = new VersionsCommand(); |
||
34 | $default_commands[] = new BackportCommand(); |
||
35 | $default_commands[] = new ChangeLogCloneCommand(); |
||
36 | |||
37 | return $default_commands; |
||
1 ignored issue
–
show
|
|||
38 | } |
||
39 | |||
40 | } |
||
41 |
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.