Completed
Pull Request — master (#30)
by Matthew
23:29 queued 08:10
created

MessageableJobWithId::toMessage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Dtc\QueueBundle\Model;
4
5
abstract class MessageableJobWithId extends MessageableJob
6
{
7
    /**
8
     * @return string A json_encoded version of a queueable version of the object
9
     */
10 27
    public function toMessage()
11
    {
12 27
        $arr = $this->toMessageArray();
13 27
        $arr['id'] = $this->getId();
14
15 27
        return json_encode($arr);
16
    }
17
18
    /**
19
     * @param string $message a json_encoded version of the object
20
     */
21 19
    public function fromMessage($message)
22
    {
23 19
        $arr = json_decode($message, true);
24 19
        if (is_array($arr)) {
25 19
            $this->fromMessageArray($arr);
26 19
            if (isset($arr['id'])) {
27 19
                $this->setId($arr['id']);
28
            }
29
        }
30 19
    }
31
}
32