Passed
Push — master ( 505a98...965270 )
by Vladimir
07:00
created

RabbitMQClient::getConnect()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2.0054

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 12
ccs 8
cts 9
cp 0.8889
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 2.0054
1
<?php
2
3
/**
4
 * This file is part of the `tvi/monitor-bundle` project.
5
 *
6
 * (c) https://github.com/turnaev/monitor-bundle/graphs/contributors
7
 *
8
 * For the full copyright and license information, please view the LICENSE.md
9
 * file that was distributed with this source code.
10
 */
0 ignored issues
show
Coding Style introduced by
PHP version not specified
Loading history...
Coding Style introduced by
Missing @category tag in file comment
Loading history...
Coding Style introduced by
Missing @package tag in file comment
Loading history...
Coding Style introduced by
Missing @author tag in file comment
Loading history...
Coding Style introduced by
Missing @license tag in file comment
Loading history...
Coding Style introduced by
Missing @link tag in file comment
Loading history...
11
12
namespace Tvi\MonitorBundle\Check\rabbitmq;
13
14
use PhpAmqpLib\Connection\AMQPConnection;
15
use Tvi\MonitorBundle\Exception\FeatureRequired;
16
17
/**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
18
 * @author Vladimir Turnaev <[email protected]>
19
 */
0 ignored issues
show
Coding Style introduced by
Missing @category tag in class comment
Loading history...
Coding Style introduced by
Missing @package tag in class comment
Loading history...
Coding Style introduced by
Missing @license tag in class comment
Loading history...
Coding Style introduced by
Missing @link tag in class comment
Loading history...
20
class RabbitMQClient
21
{
22
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
23
     * @var string
24
     */
25
    protected $host;
26
27
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
28
     * @var int
29
     */
30
    protected $port;
31
32
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
33
     * @var string
34
     */
35
    protected $user;
36
37
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
38
     * @var string
39
     */
40
    protected $password;
41
42
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
43
     * @var string
44
     */
45
    protected $vhost;
46
47
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
48
     * @param ?string  $host
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
49
     * @param ?integer $port
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
50
     * @param ?string  $user
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
51
     * @param ?string  $password
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
52
     * @param ?string  $vhost
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
53
     * @param ?string  $dsn
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
54
     */
55 6
    public function __construct($host = 'localhost',
56
                                $port = 5672,
0 ignored issues
show
Coding Style introduced by
Multi-line function declaration not indented correctly; expected 8 spaces but found 32
Loading history...
57
                                $user = 'guest',
0 ignored issues
show
Coding Style introduced by
Multi-line function declaration not indented correctly; expected 8 spaces but found 32
Loading history...
58
                                $password = 'guest',
0 ignored issues
show
Coding Style introduced by
Multi-line function declaration not indented correctly; expected 8 spaces but found 32
Loading history...
59
                                $vhost = '/',
0 ignored issues
show
Coding Style introduced by
Multi-line function declaration not indented correctly; expected 8 spaces but found 32
Loading history...
60
                                $dsn = null
0 ignored issues
show
Coding Style introduced by
Multi-line function declaration not indented correctly; expected 8 spaces but found 32
Loading history...
61
    ) {
62 6
        if ($dsn) {
63
            $params = [
64 3
                'host' => $host,
65 3
                'port' => $port,
66 3
                'user' => $user,
67 3
                'pass' => $password,
68 3
                'path' => $vhost,
69
            ];
70 3
            $dsn = parse_url($dsn);
71
72 3
            $dnsConfig = array_merge($params, $dsn);
73
74 3
            $host = $dnsConfig['host'] ?? $host;
75 3
            $port = $dnsConfig['port'] ?? $port;
76 3
            $user = $dnsConfig['user'] ?? $user;
77 3
            $password = $dnsConfig['pass'] ?? $password;
78 3
            $vhost = $dnsConfig['path'] ?? $vhost;
79
        }
80
81 6
        $this->host = $host;
82 6
        $this->port = $port;
83 6
        $this->user = $user;
84 6
        $this->password = $password;
85 6
        $this->vhost = $vhost;
86 6
    }
87
88 6
    public function getConnect(): AMQPConnection
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function getConnect()
Loading history...
89
    {
90 6
        if (!class_exists('PhpAmqpLib\Connection\AMQPConnection')) {
91
            throw new FeatureRequired('PhpAmqpLib is not installed');
92
        }
93
94 6
        return new AMQPConnection(
0 ignored issues
show
Deprecated Code introduced by
The class PhpAmqpLib\Connection\AMQPConnection has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

94
        return /** @scrutinizer ignore-deprecated */ new AMQPConnection(
Loading history...
95 6
            $this->host,
96 6
            $this->port,
97 6
            $this->user,
98 6
            $this->password,
99 6
            $this->vhost
100
        );
101
    }
102
}
103