Passed
Push — master ( 2a1c3b...234454 )
by Benjamin
03:55 queued 01:54
created

AmqpTransport::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 2
dl 0
loc 5
ccs 4
cts 4
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of the php-gelf package.
5
 *
6
 * (c) Benjamin Zikarsky <http://benjamin-zikarsky.de>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Gelf\Transport;
13
14
use AMQPExchange;
15
use AMQPQueue;
16
use Gelf\Encoder\JsonEncoder as DefaultEncoder;
17
use Gelf\MessageInterface as Message;
18
19
/**
20
 * Class AmqpTransport
21
 *
22
 * @package Gelf\Transport
23
 * @see http://php.net/manual/pl/book.amqp.php
24
 */
25
class AmqpTransport extends AbstractTransport
26
{
27
    /**
28
     * @var AMQPExchange $exchange
29
     */
30
    protected $exchange;
31
32
    /**
33
     * @var AMQPQueue $exchange
34
     */
35
    protected $queue;
36
37
    /**
38
     * @param AMQPExchange $exchange
39
     * @param AMQPQueue $queue
40
     */
41 4
    public function __construct(AMQPExchange $exchange, AMQPQueue $queue)
42
    {
43 4
        $this->queue = $queue;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 10 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
44 4
        $this->exchange = $exchange;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 7 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
45 4
        $this->messageEncoder = new DefaultEncoder();
46 4
    }
47
48
    /**
49
     * @inheritdoc
50
     */
51 1
    public function send(Message $message)
52
    {
53 1
        $rawMessage = $this->getMessageEncoder()->encode($message);
54
55
        $attributes = array(
56
            'Content-type' => 'application/json'
57 1
        );
58
59
        // if queue is durable then mark message as 'persistent'
60 1
        if (($this->queue->getFlags() & AMQP_DURABLE) > 0) {
61
            $attributes['delivery_mode'] = 2;
62
        }
63
64 1
        $this->exchange->publish(
65 1
            $rawMessage,
66 1
            $this->queue->getName(),
67 1
            AMQP_NOPARAM,
68
            $attributes
69 1
        );
70 1
        return 1;
71
    }
72
}
0 ignored issues
show
Coding Style introduced by
As per coding style, files should not end with a newline character.

This check marks files that end in a newline character, i.e. an empy line.

Loading history...
73