Completed
Pull Request — master (#30)
by Matthew
23:29 queued 08:10
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 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