Completed
Push — master ( 0ef30a...eb3939 )
by Kevin
03:35
created

Application   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 47
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getHelp() 0 4 1
A getDefaultCommands() 0 8 1
1
<?php
2
3
namespace PCextreme\Cloudstack\Console;
4
5
use Symfony\Component\Console\Application as BaseApplication;
6
7
class Application extends BaseApplication
8
{
9
    /**
10
     * @var string
11
     */
12
    private static $logo = "   ___  ___          _
13
  / _ \/ __\_____  _| |_ _ __ ___ _ __ ___   ___
14
 / /_)/ /  / _ \ \/ / __| '__/ _ \ '_ ` _ \ / _ \
15
/ ___/ /__|  __/>  <| |_| | |  __/ | | | | |  __/
16
\/   \____/\___/_/\_\\\__|_|  \___|_| |_| |_|\___|
17
18
";
19
20
    /**
21
     * Create a new instance of the application.
22
     *
23
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
24
     */
25
    public function __construct()
26
    {
27
        parent::__construct('PCextreme Cloudstack client');
28
    }
29
30
    /**
31
     * Gets the help message.
32
     *
33
     * @return string A help message
34
     */
35
    public function getHelp()
36
    {
37
        return self::$logo . parent::getHelp();
38
    }
39
40
    /**
41
     * Gets the default commands that should always be available.
42
     *
43
     * @return array
44
     */
45
    protected function getDefaultCommands()
46
    {
47
        $commands = array_merge(parent::getDefaultCommands(), [
48
            new ApiListCommand,
49
        ]);
50
51
        return $commands;
0 ignored issues
show
Best Practice introduced by
The expression return $commands; seems to be an array, but some of its elements' types (PCextreme\Cloudstack\Console\ApiListCommand) are incompatible with the return type of the parent method Symfony\Component\Consol...ion::getDefaultCommands of type array<Symfony\Component\...le\Command\ListCommand>.

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...
52
    }
53
}
54