Completed
Pull Request — master (#19)
by Michal
08:13
created

RabbitMQDriver::connect()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 10
cts 10
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 8
nc 1
nop 1
crap 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