Failed Conditions
Push — master ( acad7e...bfa4e7 )
by Alexander
02:33
created

Application::getDefaultCommands()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 23
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 23
ccs 0
cts 18
cp 0
rs 9.0856
c 0
b 0
f 0
cc 2
eloc 17
nc 2
nop 0
crap 6
1
<?php
2
/**
3
 * This file is part of the SVN-Buddy 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/svn-buddy
9
 */
10
11
namespace ConsoleHelpers\SVNBuddy;
12
13
14
use ConsoleHelpers\ConsoleKit\Application as BaseApplication;
15
use ConsoleHelpers\ConsoleKit\Container as BaseContainer;
16
use ConsoleHelpers\SVNBuddy\Command\AggregateCommand;
17
use ConsoleHelpers\SVNBuddy\Command\CleanupCommand;
18
use ConsoleHelpers\SVNBuddy\Command\CommitCommand;
19
use ConsoleHelpers\SVNBuddy\Command\CompletionCommand;
20
use ConsoleHelpers\SVNBuddy\Command\ConfigCommand;
21
use ConsoleHelpers\SVNBuddy\Command\ConflictsCommand;
22
use ConsoleHelpers\SVNBuddy\Command\Dev\MigrationCreateCommand;
23
use ConsoleHelpers\SVNBuddy\Command\Dev\PharCreateCommand;
24
use ConsoleHelpers\SVNBuddy\Command\LogCommand;
25
use ConsoleHelpers\SVNBuddy\Command\MergeCommand;
26
use ConsoleHelpers\SVNBuddy\Command\RevertCommand;
27
use ConsoleHelpers\SVNBuddy\Command\SelfUpdateCommand;
28
use ConsoleHelpers\SVNBuddy\Command\UpdateCommand;
29
use ConsoleHelpers\SVNBuddy\Repository\Connector\Connector;
30
31
class Application extends BaseApplication
32
{
33
34
	/**
35
	 * Creates application.
36
	 *
37
	 * @param BaseContainer $container Container.
38
	 */
39
	public function __construct(BaseContainer $container)
40
	{
41
		parent::__construct($container);
42
43
		$helper_set = $this->getHelperSet();
44
		$helper_set->set($this->dic['date_helper']);
45
		$helper_set->set($this->dic['size_helper']);
46
		$helper_set->set($this->dic['output_helper']);
47
48
		set_time_limit(0);
49
		ini_set('memory_limit', -1);
50
51
		putenv('LC_CTYPE=en_US.UTF-8'); // For SVN.
52
	}
53
54
	/**
55
	 * Returns the long version of the application.
56
	 *
57
	 * @return string The long application version
58
	 *
59
	 * @api
60
	 */
61
	public function getLongVersion()
62
	{
63
		$version = parent::getLongVersion();
64
65
		/** @var Connector $repository_connector */
66
		$repository_connector = $this->dic['repository_connector'];
67
		$client_version = $repository_connector->getCommand('', '--version --quiet')->run();
68
69
		return $version . ' (SVN <comment>v' . trim($client_version) . '</comment>)';
70
	}
71
72
	/**
73
	 * {@inheritdoc}
74
	 */
75
	protected function getDefaultCommands()
76
	{
77
		$default_commands = parent::getDefaultCommands();
78
79
		$default_commands[] = new MergeCommand();
80
		$default_commands[] = new CleanupCommand();
81
		$default_commands[] = new RevertCommand();
82
		$default_commands[] = new LogCommand();
83
		$default_commands[] = new UpdateCommand();
84
		$default_commands[] = new CommitCommand();
85
		$default_commands[] = new ConflictsCommand();
86
		$default_commands[] = new AggregateCommand();
87
		$default_commands[] = new CompletionCommand();
88
		$default_commands[] = new ConfigCommand();
89
		$default_commands[] = new SelfUpdateCommand();
90
91
		if ( !$this->isPharFile() ) {
92
			$default_commands[] = new MigrationCreateCommand();
93
			$default_commands[] = new PharCreateCommand();
94
		}
95
96
		return $default_commands;
1 ignored issue
show
Best Practice introduced by
The expression return $default_commands; seems to be an array, but some of its elements' types (ConsoleHelpers\SVNBuddy\...d\Dev\PharCreateCommand) 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...
97
	}
98
99
}
100