JobMarshaler   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 3
dl 0
loc 22
ccs 0
cts 12
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A unmarshal() 0 8 2
A marshal() 0 4 1
1
<?php
2
namespace Disque\Queue\Marshal;
3
4
use Disque\Queue\Job;
5
use Disque\Queue\JobInterface;
6
7
/**
8
 * Serialize and deserialize the job body
9
 *
10
 * Serialize the job body when adding the job to the queue,
11
 * deserialize it and instantiate a new Job object when reading the job
12
 * from the queue.
13
 *
14
 * This marshaler uses JSON serialization for the whole Job body.
15
 */
16
class JobMarshaler implements MarshalerInterface
17
{
18
    /**
19
     * @inheritdoc
20
     */
21
    public function unmarshal($source)
22
    {
23
        $body = json_decode($source, true);
24
        if (is_null($body)) {
25
            throw new MarshalException("Could not deserialize {$source}");
26
        }
27
        return new Job($body);
28
    }
29
30
    /**
31
     * @inheritdoc
32
     */
33
    public function marshal(JobInterface $job)
34
    {
35
        return json_encode($job->getBody());
36
    }
37
}
38