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

Message::fromArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 2
crap 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