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

CacheResolved::jsonDeserialize()   A

Complexity

Conditions 3
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.4285
c 0
b 0
f 0
cc 3
eloc 7
nc 3
nop 1
1
<?php
2
namespace Liip\ImagineBundle\Async;
3
4
use Enqueue\Util\JSON;
5
6
class CacheResolved implements \JsonSerializable
7
{
8
    /**
9
     * @var string
10
     */
11
    private $path;
12
13
    /**
14
     * @var \string[]
15
     */
16
    private $uris;
17
    
18
    /**
19
     * @param string $path
20
     * @param string[]|null $uris
21
     */
22
    public function __construct($path, array $uris)
23
    {
24
        $this->path = $path;
25
        $this->uris = $uris;
0 ignored issues
show
Documentation Bug introduced by
It seems like $uris of type array<integer,string> is incompatible with the declared type array<integer,object<string>> of property $uris.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
26
    }
27
28
    /**
29
     * @return string
30
     */
31
    public function getPath()
32
    {
33
        return $this->path;
34
    }
35
36
    /**
37
     * @return \string[]
38
     */
39
    public function getUris()
40
    {
41
        return $this->uris;
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47
    public function jsonSerialize()
48
    {
49
        return array('path' => $this->path, 'uris' => $this->uris);
50
    }
51
52
    /**
53
     * @param string $json
54
     *
55
     * @return static
56
     */
57
    public static function jsonDeserialize($json)
58
    {
59
        $data = JSON::decode($json);
60
61
        if (empty($data['path'])) {
62
            throw new \LogicException('The message does not contain "path" but it is required.');
63
        }
64
65
        if (empty($data['uris'])) {
66
            throw new \LogicException('The message uris must not be empty array.');
67
        }
68
69
        return new static($data['path'], $data['uris']);
70
    }
71
}
72