Passed
Pull Request — master (#9)
by Nicolas
03:16
created

InMemory   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 92.31%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 3
dl 0
loc 55
ccs 24
cts 26
cp 0.9231
rs 10
c 0
b 0
f 0

8 Methods

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