Completed
Push — master ( ccbe64...bcccab )
by Thomas Mauro
05:56
created

AMQP::createChannelResource()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 0
cts 0
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
namespace AMQPAL\Adapter\AMQP;
4
5
use AMQPAL\Adapter\AMQP\Options\ConnectionOptions;
6
use AMQPAL\Adapter\AdapterInterface;
7
use AMQPAL\Adapter\Exception;
8
9
/**
10
 * Class AMQP
11
 *
12
 * @package AMQPAL\Adapter\AMQP
13
 */
14
class AMQP implements AdapterInterface
15
{
16
    /**
17
     * @var Connection
18
     */
19
    protected $connection;
20
21
    /**
22
     * AMQP constructor.
23
     *
24
     * @param Connection|ConnectionOptions|array|\Traversable|\AMQPConnection $connection
25
     * @param Channel    $channelPrototype
26
     * @throws Exception\InvalidArgumentException
27
     * @throws Exception\BadMethodCallException
28
     */
29 8
    public function __construct($connection, Channel $channelPrototype = null)
30
    {
31 8
        if (!$connection instanceof Connection) {
32 8
            $connection = new Connection($connection, $channelPrototype);
0 ignored issues
show
Bug introduced by
It seems like $connection defined by new \AMQPAL\Adapter\AMQP...ion, $channelPrototype) on line 32 can also be of type array or object<Traversable>; however, AMQPAL\Adapter\AMQP\Connection::__construct() does only seem to accept object<AMQPConnection>|o...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...
33
        }
34 8
        $this->registerConnection($connection);
35 8
    }
36
37
    /**
38
     * @param Connection $connection
39
     */
40 8
    public function registerConnection(Connection $connection)
41
    {
42 8
        $this->connection = $connection;
43 8
    }
44
45
    /**
46
     * @return Connection
47
     */
48 8
    public function getConnection()
49
    {
50 8
        return $this->connection;
51
    }
52
}
53