Connection   A
last analyzed

Complexity

Total Complexity 23

Size/Duplication

Total Lines 169
Duplicated Lines 9.47 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 95.83%

Importance

Changes 0
Metric Value
dl 16
loc 169
c 0
b 0
f 0
wmc 23
lcom 1
cbo 1
ccs 46
cts 48
cp 0.9583
rs 10

17 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __destruct() 0 4 1
A getHost() 0 4 1
A getLogin() 0 4 1
A getPassword() 0 4 1
A getPort() 0 4 1
A getVhost() 0 4 1
A setHost() 8 8 2
A setLogin() 0 8 2
A setPassword() 0 8 2
A setPort() 8 8 2
A setVhost() 0 8 2
A connect() 0 8 2
A close() 0 4 1
A isConnected() 0 4 1
A reconnect() 0 4 1
A getDelegate() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace TreeHouse\Queue\Amqp\Driver\Amqp;
4
5
use TreeHouse\Queue\Amqp\ConnectionInterface;
6
use TreeHouse\Queue\Exception\ConnectionException;
7
8
class Connection implements ConnectionInterface
9
{
10
    /**
11
     * @var \AMQPConnection
12
     */
13
    protected $delegate;
14
15
    /**
16
     * @param \AMQPConnection $delegate
17
     */
18 43
    public function __construct(\AMQPConnection $delegate)
19
    {
20 43
        $this->delegate = $delegate;
21 43
    }
22
23
    /**
24
     * Closes connection on destruct.
25
     */
26 41
    public function __destruct()
27
    {
28 41
        $this->close();
29 41
    }
30
31
    /**
32
     * @inheritdoc
33
     */
34 2
    public function getHost()
35
    {
36 2
        return $this->delegate->getHost();
37
    }
38
39
    /**
40
     * @inheritdoc
41
     */
42 2
    public function getLogin()
43
    {
44 2
        return $this->delegate->getLogin();
45
    }
46
47
    /**
48
     * @inheritdoc
49
     */
50 2
    public function getPassword()
51
    {
52 2
        return $this->delegate->getPassword();
53
    }
54
55
    /**
56
     * @inheritdoc
57
     */
58 2
    public function getPort()
59
    {
60 2
        return $this->delegate->getPort();
61
    }
62
63
    /**
64
     * @inheritdoc
65
     */
66 2
    public function getVhost()
67
    {
68 2
        return $this->delegate->getVhost();
69
    }
70
71
    /**
72
     * @inheritdoc
73
     */
74 2 View Code Duplication
    public function setHost($host)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
75
    {
76
        try {
77 2
            return $this->delegate->setHost($host);
78 1
        } catch (\AMQPConnectionException $e) {
79 1
            throw new ConnectionException($e->getMessage(), $e->getCode(), $e);
80
        }
81
    }
82
83
    /**
84
     * @inheritdoc
85
     */
86 2
    public function setLogin($login)
87
    {
88
        try {
89 2
            return $this->delegate->setLogin($login);
90 1
        } catch (\AMQPConnectionException $e) {
91 1
            throw new ConnectionException($e->getMessage(), $e->getCode(), $e);
92
        }
93
    }
94
95
    /**
96
     * @inheritdoc
97
     */
98 2
    public function setPassword($password)
99
    {
100
        try {
101 2
            return $this->delegate->setPassword($password);
102 1
        } catch (\AMQPConnectionException $e) {
103 1
            throw new ConnectionException($e->getMessage(), $e->getCode(), $e);
104
        }
105
    }
106
107
    /**
108
     * @inheritdoc
109
     */
110 2 View Code Duplication
    public function setPort($port)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
111
    {
112
        try {
113 2
            return $this->delegate->setPort($port);
114 1
        } catch (\AMQPConnectionException $e) {
115 1
            throw new ConnectionException($e->getMessage(), $e->getCode(), $e);
116
        }
117
    }
118
119
    /**
120
     * @inheritdoc
121
     */
122 2
    public function setVhost($vhost)
123
    {
124
        try {
125 2
            return $this->delegate->setVhost($vhost);
126 1
        } catch (\AMQPConnectionException $e) {
127 1
            throw new ConnectionException($e->getMessage(), $e->getCode(), $e);
128
        }
129
    }
130
131
    /**
132
     * @inheritdoc
133
     */
134 30
    public function connect()
135
    {
136
        try {
137 30
            return $this->delegate->connect();
138
        } catch (\AMQPConnectionException $e) {
139
            throw new ConnectionException($e->getMessage(), $e->getCode(), $e);
140
        }
141
    }
142
143
    /**
144
     * @inheritdoc
145
     */
146 42
    public function close()
147
    {
148 42
        return $this->delegate->disconnect();
149
    }
150
151
    /**
152
     * @inheritdoc
153
     */
154 29
    public function isConnected()
155
    {
156 29
        return $this->delegate->isConnected();
157
    }
158
159
    /**
160
     * @inheritdoc
161
     */
162 1
    public function reconnect()
163
    {
164 1
        return $this->delegate->reconnect();
165
    }
166
167
    /**
168
     * @inheritdoc
169
     *
170
     * @return \AMQPConnection
171
     */
172 27
    public function getDelegate()
173
    {
174 27
        return $this->delegate;
175
    }
176
}
177