console-helpers /
jira-cli
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\DownloadAttachmentCommand; |
||
| 15 | use ConsoleHelpers\ConsoleKit\Application as BaseApplication; |
||
| 16 | use ConsoleHelpers\JiraCLI\Command\VersionsCommand; |
||
| 17 | use Symfony\Component\Console\Command\Command; |
||
| 18 | |||
| 19 | class Application extends BaseApplication |
||
| 20 | { |
||
| 21 | |||
| 22 | /** |
||
| 23 | * Initializes all the composer commands. |
||
| 24 | * |
||
| 25 | * @return Command[] An array of default Command instances. |
||
| 26 | */ |
||
| 27 | protected function getDefaultCommands() |
||
| 28 | { |
||
| 29 | $default_commands = parent::getDefaultCommands(); |
||
| 30 | $default_commands[] = new DownloadAttachmentCommand(); |
||
| 31 | $default_commands[] = new VersionsCommand(); |
||
| 32 | |||
| 33 | return $default_commands; |
||
|
0 ignored issues
–
show
|
|||
| 34 | } |
||
| 35 | |||
| 36 | } |
||
| 37 |
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_functionexpects aPostobject, and outputs the author of the post. The base classPostreturns a simple string and outputting a simple string will work just fine. However, the child classBlogPostwhich is a sub-type ofPostinstead decided to return anobject, and is therefore violating the SOLID principles. If aBlogPostwere passed tomy_function, PHP would not complain, but ultimately fail when executing thestrtouppercall in its body.