Completed
Pull Request — master (#30)
by Matthew
18:57 queued 16:20
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 17
    public function toMessage()
11
    {
12 17
        $arr = $this->toMessageArray();
13 17
        $arr['id'] = $this->getId();
14
15 17
        return json_encode($arr);
16
    }
17
18
    /**
19
     * @param string $message a json_encoded version of the object
20
     */
21 12
    public function fromMessage($message)
22
    {
23 12
        $arr = json_decode($message, true);
24 12
        if (is_array($arr)) {
25 12
            $this->fromMessageArray($arr);
26 12
            if (isset($arr['id'])) {
27 12
                $this->setId($arr['id']);
28
            }
29
        }
30 12
    }
31
}
32