Completed
Push — master ( 40b87c...f82b1c )
by Matthew
04:37
created

MessageableJob   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 12
lcom 2
cbo 1
dl 0
loc 53
ccs 26
cts 26
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A toMessageArray() 0 9 2
A toMessage() 0 4 1
A fromMessage() 0 7 2
B fromMessageArray() 0 21 7
1
<?php
2
3
namespace Dtc\QueueBundle\Model;
4
5
abstract class MessageableJob extends Job
6
{
7 12
    protected function toMessageArray()
8
    {
9
        return array(
10 12
            'worker' => $this->getWorkerName(),
11 12
            'args' => $this->getArgs(),
12 12
            'method' => $this->getMethod(),
13 12
            'expiresAt' => ($expiresAt = $this->getExpiresAt()) ? $expiresAt->format('U.u') : null,
14
        );
15
    }
16
17
    /**
18
     * @return string A json_encoded version of a queueable version of the object
19
     */
20 6
    public function toMessage()
21
    {
22 6
        return json_encode($this->toMessageArray());
23
    }
24
25
    /**
26
     * @param string $message a json_encoded version of the object
27
     */
28 5
    public function fromMessage($message)
29
    {
30 5
        $arr = json_decode($message, true);
31 5
        if (is_array($arr)) {
32 5
            $this->fromMessageArray($arr);
33
        }
34 5
    }
35
36 11
    protected function fromMessageArray(array $arr)
37
    {
38 11
        if (isset($arr['worker'])) {
39 11
            $this->setWorkerName($arr['worker']);
40
        }
41 11
        if (isset($arr['args'])) {
42 11
            $this->setArgs($arr['args']);
43
        }
44 11
        if (isset($arr['method'])) {
45 11
            $this->setMethod($arr['method']);
46
        }
47 11
        if (isset($arr['expiresAt'])) {
48 2
            $expiresAt = $arr['expiresAt'];
49 2
            if ($expiresAt) {
50 2
                $dateTime = \DateTime::createFromFormat('U.u', $expiresAt);
51 2
                if ($dateTime) {
52 2
                    $this->setExpiresAt($dateTime);
53
                }
54
            }
55
        }
56 11
    }
57
}
58