Completed
Pull Request — master (#19)
by Michal
03:25
created

RabbitMQDriver   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 7
dl 0
loc 73
ccs 34
cts 34
cp 1
rs 10
c 0
b 0
f 0

10 Methods

Rating   Name   Duplication   Size   Complexity  
A extensions() 0 4 1
A classes() 0 4 1
A type() 0 4 1
A defaultCredentials() 0 11 1
A getCredentialsForm() 0 4 1
A getHeaderManager() 0 4 1
A getPermissions() 0 4 1
A connect() 0 12 1
A getFormManager() 0 4 1
A getDataManager() 0 4 1
1
<?php
2
3
namespace Adminerng\Drivers\RabbitMQ;
4
5
use Adminerng\Core\Driver\AbstractDriver;
6
use Adminerng\Drivers\RabbitMQ\Forms\RabbitMQCredentialsForm;
7
8
class RabbitMQDriver extends AbstractDriver
9
{
10
    const TYPE_QUEUE = 'queue';
11
12
    private $credentials = [];
13
14
    private $client;
15
16 2
    public function extensions()
17
    {
18 2
        return ['curl'];
19
    }
20
21 2
    public function classes()
22
    {
23 2
        return ['PhpAmqpLib\Connection\AMQPStreamConnection'];
24
    }
25
26 2
    public function type()
27
    {
28 2
        return 'rabbitmq';
29
    }
30
31 2
    public function defaultCredentials()
32
    {
33
        return [
34 2
            'host' => 'localhost',
35 1
            'port' => '5672',
36 1
            'api_host' => 'localhost',
37 1
            'api_port' => '15672',
38 1
            'user' => 'guest',
39 1
            'password' => 'guest',
40 1
        ];
41
    }
42
43 2
    public function getCredentialsForm()
44
    {
45 2
        return new RabbitMQCredentialsForm();
46
    }
47
48 2
    public function connect(array $credentials)
49
    {
50 2
        $this->credentials = $credentials;
51
52 2
        $this->client = new RabbitMQManagementApiClient(
53 2
            $this->credentials['api_host'],
54 2
            $this->credentials['api_port'],
55 2
            $this->credentials['user'],
56 2
            $this->credentials['password']
57 1
        );
58 2
        $this->client->overview();
59 2
    }
60
61 2
    protected function getFormManager()
62
    {
63 2
        return new RabbitMQFormManager($this->dataManager());
0 ignored issues
show
Compatibility introduced by
$this->dataManager() of type object<Adminerng\Core\Da...r\DataManagerInterface> is not a sub-type of object<Adminerng\Drivers...MQ\RabbitMQDataManager>. It seems like you assume a concrete implementation of the interface Adminerng\Core\DataManager\DataManagerInterface to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
64
    }
65
66 2
    protected function getHeaderManager()
67
    {
68 2
        return new RabbitMQHeaderManager();
69
    }
70
71 2
    protected function getPermissions()
72
    {
73 2
        return new RabbitMQPermissions();
74
    }
75
76 2
    protected function getDataManager()
77
    {
78 2
        return new RabbitMQDataManager($this->credentials, $this->client, $this->translator);
79
    }
80
}
81