Test Failed
Pull Request — master (#9)
by Nicolas
10:03 queued 04:15
created

InMemory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 2
c 0
b 0
f 0
lcom 0
cbo 4
dl 0
loc 30
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B build() 0 24 2
1
<?php
2
3
namespace Puzzle\AMQP\Messages;
4
5
use Puzzle\AMQP\Workers\MessageAdapter;
6
use Puzzle\AMQP\Messages\Bodies\NullBody;
7
8
class InMemory
9
{
10
    /**
11
     * @return \Puzzle\AMQP\ReadableMessage
12
     */
13
    public static function build($routingKey, Body $body = null, array $additionalHeaders = [], array $additionalAttributes = [])
14
    {
15
        if(! $body instanceof Body)
16
        {
17
            $body = new NullBody();
18
        }
19
20
        $attributes = array_merge([
21
            'content_type' => $body->getContentType(),
22
            'routing_key' => $routingKey,
23
            'content_encoding' => 'utf8',
24
            'message_id' => uniqid(true),
25
        ], $additionalAttributes);
26
27
        $attributes['headers'] = array_merge([
28
            'routing_key' => $routingKey,
29
            'app_id' => 'memory',
30
            'message_datetime' => date('Y-m-d H:i:s'),
31
        ], $additionalHeaders);
32
33
        return new MessageAdapter(
34
            new \Swarrot\Broker\Message($body->format(), $attributes)
35
        );
36
    }
37
}
38