Completed
Push — master ( 626232...f01a8c )
by Thibaud
02:14
created

Message   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 0
cbo 2
dl 0
loc 48
ccs 10
cts 10
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 2
A getBody() 0 4 1
A getCorrelationId() 0 4 1
A fromArray() 0 4 1
1
<?php
2
3
namespace Alchemy\Queue;
4
5
use Ramsey\Uuid\Uuid;
6
7
class Message
8
{
9
    /**
10
     * @param array $data
11
     * @param null $correlationId
12
     * @return Message
13
     */
14 4
    public static function fromArray(array $data, $correlationId = null)
15
    {
16 4
        return new self(json_encode($data), $correlationId);
17
    }
18
19
    /**
20
     * @var string
21
     */
22
    private $body;
23
24
    /**
25
     * @var string
26
     */
27
    private $correlationId;
28
29
    /**
30
     * @param string $body
31
     * @param null|string $correlationId
32
     */
33 48
    public function __construct($body, $correlationId = null)
34
    {
35 48
        $this->body = (string) $body;
36 48
        $this->correlationId = (string) ($correlationId ?: Uuid::uuid4()->toString());
37 48
    }
38
39
    /**
40
     * @return string
41
     */
42 20
    public function getBody()
43
    {
44 20
        return $this->body;
45
    }
46
47
    /**
48
     * @return string
49
     */
50 24
    public function getCorrelationId()
51
    {
52 24
        return $this->correlationId;
53
    }
54
}
55