Channel   A
last analyzed

Complexity

Total Complexity 16

Size/Duplication

Total Lines 104
Duplicated Lines 38.46 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 79.41%

Importance

Changes 0
Metric Value
dl 40
loc 104
c 0
b 0
f 0
wmc 16
lcom 1
cbo 2
ccs 27
cts 34
cp 0.7941
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getConnection() 0 4 1
A getChannelId() 0 4 1
A basicQos() 10 10 3
A startTransaction() 10 10 3
A commitTransaction() 10 10 3
A rollbackTransaction() 10 10 3
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\ChannelInterface;
6
use TreeHouse\Queue\Amqp\ConnectionInterface;
7
use TreeHouse\Queue\Exception\ChannelException;
8
use TreeHouse\Queue\Exception\ConnectionException;
9
10
class Channel implements ChannelInterface
11
{
12
    /**
13
     * @var \AMQPChannel
14
     */
15
    protected $delegate;
16
17
    /**
18
     * @var ConnectionInterface
19
     */
20
    protected $connection;
21
22
    /**
23
     * @param \AMQPChannel        $delegate
24
     * @param ConnectionInterface $connection
25
     */
26 27
    public function __construct(\AMQPChannel $delegate, ConnectionInterface &$connection)
27
    {
28 27
        $this->delegate = $delegate;
29 27
        $this->connection = &$connection;
30 27
    }
31
32
    /**
33
     * @inheritdoc
34
     */
35 3
    public function getConnection()
36
    {
37 3
        return $this->connection;
38
    }
39
40
    /**
41
     * @inheritdoc
42
     */
43 1
    public function getChannelId()
44
    {
45 1
        return $this->delegate->getChannelId();
46
    }
47
48
    /**
49
     * @inheritdoc
50
     */
51 2 View Code Duplication
    public function basicQos($prefetchSize, $prefetchCount)
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...
52
    {
53
        try {
54 2
            return $this->delegate->qos($prefetchSize, $prefetchCount);
55 1
        } catch (\AMQPChannelException $e) {
56
            throw new ChannelException($e->getMessage(), $e->getCode(), $e);
57 1
        } catch (\AMQPConnectionException $e) {
58 1
            throw new ConnectionException($e->getMessage(), $e->getCode(), $e);
59
        }
60
    }
61
62
    /**
63
     * @inheritdoc
64
     */
65 3 View Code Duplication
    public function startTransaction()
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...
66
    {
67
        try {
68 3
            return $this->delegate->startTransaction();
69 1
        } catch (\AMQPChannelException $e) {
70 1
            throw new ChannelException($e->getMessage(), $e->getCode(), $e);
71
        } catch (\AMQPConnectionException $e) {
72
            throw new ConnectionException($e->getMessage(), $e->getCode(), $e);
73
        }
74
    }
75
76
    /**
77
     * @inheritdoc
78
     */
79 3 View Code Duplication
    public function commitTransaction()
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...
80
    {
81
        try {
82 3
            return $this->delegate->commitTransaction();
83 2
        } catch (\AMQPChannelException $e) {
84 2
            throw new ChannelException($e->getMessage(), $e->getCode(), $e);
85
        } catch (\AMQPConnectionException $e) {
86
            throw new ConnectionException($e->getMessage(), $e->getCode(), $e);
87
        }
88
    }
89
90
    /**
91
     * @inheritdoc
92
     */
93 2 View Code Duplication
    public function rollbackTransaction()
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...
94
    {
95
        try {
96 2
            return $this->delegate->rollbackTransaction();
97 2
        } catch (\AMQPChannelException $e) {
98 2
            throw new ChannelException($e->getMessage(), $e->getCode(), $e);
99
        } catch (\AMQPConnectionException $e) {
100
            throw new ConnectionException($e->getMessage(), $e->getCode(), $e);
101
        }
102
    }
103
104
    /**
105
     * @inheritdoc
106
     *
107
     * @return \AMQPChannel
108
     */
109 14
    public function getDelegate()
110
    {
111 14
        return $this->delegate;
112
    }
113
}
114