Completed
Push — master ( 6f7267...183492 )
by Stanislav
10:16
created

Application   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 114
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 10

Importance

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

11 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getDefaultCommands() 0 14 1
A getClient() 0 4 1
A setClient() 0 4 1
A getLogger() 0 4 1
A setLogger() 0 4 1
A getConfig() 0 4 1
A setConfig() 0 4 1
A getWeburgClient() 0 7 2
A setWeburgClient() 0 4 1
A createWeburgClient() 0 5 1
1
<?php
2
3
namespace Popstas\Transmission\Console;
4
5
use GuzzleHttp;
6
use Popstas\Transmission\Console\Command;
7
use Psr\Log\LoggerInterface;
8
use Stecman\Component\Symfony\Console\BashCompletion;
9
use Symfony\Component\Console\Application as BaseApplication;
10
11
class Application extends BaseApplication
12
{
13
    const VERSION = 'dev';
14
15
    /**
16
     * @var Config $config
17
     */
18
    private $config;
19
20
    /**
21
     * @var LoggerInterface $logger
22
     */
23
    private $logger;
24
25
    /**
26
     * @var TransmissionClient $client
27
     */
28
    private $client;
29
30
    /**
31
     * @var WeburgClient
32
     */
33
    private $weburgClient;
34
35
    public function __construct($name = 'Transmission CLI', $version = self::VERSION)
36
    {
37
        parent::__construct($name, $version);
38
    }
39
40
    /**
41
     * @return array|\Symfony\Component\Console\Command\Command[]
42
     */
43
    protected function getDefaultCommands()
44
    {
45
        $commands = array_merge(parent::getDefaultCommands(), [
46
            new BashCompletion\CompletionCommand(),
47
48
            new Command\StatsSend(),
49
            new Command\TorrentClean(),
50
            new Command\TorrentList(),
51
            new Command\TorrentRemoveDuplicates(),
52
            new Command\WeburgDownload(),
53
            new Command\WeburgSeriesAdd(),
54
        ]);
55
        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 (Stecman\Component\Symfon...Command\WeburgSeriesAdd) 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...
56
    }
57
58
    /**
59
     * @return TransmissionClient
60
     */
61
    public function getClient()
62
    {
63
        return $this->client;
64
    }
65
66
    /**
67
     * @param TransmissionClient $client
68
     */
69
    public function setClient($client)
70
    {
71
        $this->client = $client;
72
    }
73
74
    /**
75
     * @return LoggerInterface
76
     */
77
    public function getLogger()
78
    {
79
        return $this->logger;
80
    }
81
82
    /**
83
     * @param LoggerInterface $logger
84
     */
85
    public function setLogger($logger)
86
    {
87
        $this->logger = $logger;
88
    }
89
90
    /**
91
     * @return Config
92
     */
93
    public function getConfig()
94
    {
95
        return $this->config;
96
    }
97
98
    /**
99
     * @param Config $config
100
     */
101
    public function setConfig($config)
102
    {
103
        $this->config = $config;
104
    }
105
106
    public function getWeburgClient()
107
    {
108
        if (!isset($this->weburgClient)) {
109
            $this->weburgClient = $this->createWeburgClient();
110
        }
111
        return $this->weburgClient;
112
    }
113
114
    public function setWeburgClient($weburgClient)
115
    {
116
        $this->weburgClient = $weburgClient;
117
    }
118
119
    public function createWeburgClient()
120
    {
121
        $httpClient = new GuzzleHttp\Client();
122
        return new WeburgClient($httpClient);
123
    }
124
}
125