Test Failed
Pull Request — master (#9)
by Nicolas
03:28
created

InMemory   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 90.48%

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 8
c 1
b 1
f 0
lcom 1
cbo 3
dl 0
loc 55
ccs 19
cts 21
cp 0.9048
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getSentMessages() 0 4 1
A publish() 0 5 1
A updateMessageAttributes() 0 5 1
A getQueue() 0 4 1
A getExchange() 0 4 1
A saveMessage() 0 7 1
A dropSentMessages() 0 6 1
1
<?php
2
3
namespace Puzzle\AMQP\Clients;
4
5
use Puzzle\AMQP\Client;
6
use Puzzle\AMQP\WritableMessage;
7
use Puzzle\AMQP\Messages\InMemoryJson;
8
use Psr\Log\NullLogger;
9
use Puzzle\AMQP\Collections;
10
11
class InMemory implements Client
12
{
13
    use \Psr\Log\LoggerAwareTrait;
14
15
    private
16
        $sentMessages;
1 ignored issue
show
Coding Style introduced by
The visibility should be declared for property $sentMessages.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
17
18 14
    public function __construct()
19
    {
20 14
        $this->sentMessages = array();
21 14
        $this->logger = new NullLogger();
22 14
    }
23
24 8
    public function publish($exchangeName, WritableMessage $message)
25
    {
26 8
        $this->updateMessageAttributes($message);
27 8
        $this->saveMessage($exchangeName, $message);
28
    }
29 1
30
    private function updateMessageAttributes(WritableMessage $message)
31 1
    {
32
        $message->setAttribute('app_id', 'memory');
33
        $message->addHeader('routing_key', $message->getRoutingKey());
34
    }
35
36
    public function getQueue($queueName)
37
    {
38
        throw new \RuntimeException('This AMQP Client must be used only for sending purpose');
39 8
    }
40
41 8
    public function getExchange($exchangeName)
42 8
    {
43
        throw new \RuntimeException('This AMQP Client must be used only for sending purpose');
44 8
    }
45 8
46
    private function saveMessage($exchangeName, WritableMessage $message)
47 8
    {
48
        $this->sentMessages[] = array(
49 8
            'exchange' => $exchangeName,
50
            'message' => $message
51
        );
52 1
    }
53
54 1
    public function getSentMessages()
55
    {
56 1
        return $this->sentMessages;
57
    }
58
59
    public function dropSentMessages()
60
    {
61
        $this->sentMessages = array();
62
63
        return $this;
64
    }
65
}
66