Completed
Pull Request — master (#30)
by Matthew
18:57 queued 16:20
created

MessageableJobWithId   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 27
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A toMessage() 0 7 1
A fromMessage() 0 10 3
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