PhpAmqpLib   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 41
wmc 4
lcom 1
cbo 1
ccs 10
cts 10
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 2
A registerConnection() 0 4 1
A getConnection() 0 4 1
1
<?php
2
3
namespace AMQPAL\Adapter\PhpAmqpLib;
4
5
use PhpAmqpLib\Connection\AbstractConnection as LibConnection;
6
use AMQPAL\Adapter\AdapterInterface;
7
use AMQPAL\Adapter\Exception;
8
use AMQPAL\Adapter\PhpAmqpLib\Options\ConnectionOptions;
9
10
class PhpAmqpLib implements AdapterInterface
11
{
12
13
    /**
14
     * @var Connection
15
     */
16
    protected $connection;
17
18
    /**
19
     * PhpAmqpLib constructor.
20
     *
21
     * @param Connection|ConnectionOptions|array|\Traversable|LibConnection $connection
22
     * @param Channel                                    $channelPrototype
23
     * @throws Exception\BadMethodCallException
24
     * @throws Exception\InvalidArgumentException
25
     * @throws Exception\RuntimeException
26
     */
27 8
    public function __construct($connection, Channel $channelPrototype = null)
28
    {
29 8
        if (!$connection instanceof Connection) {
30 8
            $connection = new Connection($connection, $channelPrototype);
0 ignored issues
show
Bug introduced by
It seems like $connection defined by new \AMQPAL\Adapter\PhpA...ion, $channelPrototype) on line 30 can also be of type array or object<Traversable>; however, AMQPAL\Adapter\PhpAmqpLi...nnection::__construct() does only seem to accept object<PhpAmqpLib\Connec...ions\ConnectionOptions>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
31
        }
32 8
        $this->registerConnection($connection);
33 8
    }
34
35
    /**
36
     * @param Connection $connection
37
     */
38 8
    public function registerConnection(Connection $connection)
39
    {
40 8
        $this->connection = $connection;
41 8
    }
42
43
    /**
44
     * @return Connection
45
     */
46 8
    public function getConnection()
47
    {
48 8
        return $this->connection;
49
    }
50
}
51