Failed Conditions
Push — master ( 5433f0...117895 )
by Alexander
01:52
created

src/JiraCLI/Application.php (1 issue)

Upgrade to new PHP Analysis Engine

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
The expression return $default_commands; seems to be an array, but some of its elements' types (ConsoleHelpers\JiraCLI\C...d\ChangeLogCloneCommand) are incompatible with the return type of the parent method ConsoleHelpers\ConsoleKi...ion::getDefaultCommands of type array<Symfony\Component\...tion\CompletionCommand>.

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:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
38
	}
39
40
}
41