Completed
Push — 1.0 ( 09dc0e...a109cf )
by Maksim
9s
created

ResolveCache::jsonDeserialize()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.2
c 0
b 0
f 0
cc 4
eloc 7
nc 3
nop 1
1
<?php
2
namespace Liip\ImagineBundle\Async;
3
4
use Enqueue\Util\JSON;
5
6
class ResolveCache implements \JsonSerializable
7
{
8
    /**
9
     * @var string
10
     */
11
    private $path;
12
13
    /**
14
     * @var array|null|\string[]
15
     */
16
    private $filters;
17
18
    /**
19
     * @var bool
20
     */
21
    private $force;
22
23
    /**
24
     * @param string $path
25
     * @param string[]|null $filters
26
     * @param bool $force
27
     */
28
    public function __construct($path, array $filters = null, $force = false)
29
    {
30
        $this->path = $path;
31
        $this->filters = $filters;
32
        $this->force = $force;
33
    }
34
35
    /**
36
     * @return string
37
     */
38
    public function getPath()
39
    {
40
        return $this->path;
41
    }
42
43
    /**
44
     * @return null|\string[]
45
     */
46
    public function getFilters()
47
    {
48
        return $this->filters;
49
    }
50
51
    /**
52
     * @return bool
53
     */
54
    public function isForce()
55
    {
56
        return $this->force;
57
    }
58
59
    /**
60
     * {@inheritdoc}
61
     */
62
    public function jsonSerialize()
63
    {
64
        return array('path' => $this->path, 'filters' => $this->filters, 'force' => $this->force);
65
    }
66
67
    /**
68
     * @param string $json
69
     *
70
     * @return static
71
     */
72
    public static function jsonDeserialize($json)
73
    {
74
        $data = array_replace(array('path' => null, 'filters' => null, 'force' => false), JSON::decode($json));
75
76
        if (false == $data['path']) {
77
            throw new \LogicException('The message does not contain "path" but it is required.');
78
        }
79
80
        if (false == (is_null($data['filters']) || is_array($data['filters']))) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
81
            throw new \LogicException('The message filters could be either null or array.');
82
        }
83
84
        return new static($data['path'], $data['filters'], $data['force']);
85
    }
86
}
87