Completed
Push — 2.0 ( d9081a...4a1e3c )
by Rob
11:15
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
3
/*
4
 * This file is part of the `liip/LiipImagineBundle` project.
5
 *
6
 * (c) https://github.com/liip/LiipImagineBundle/graphs/contributors
7
 *
8
 * For the full copyright and license information, please view the LICENSE.md
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Liip\ImagineBundle\Async;
13
14
use Enqueue\Util\JSON;
15
use Liip\ImagineBundle\Exception\LogicException;
16
17
class CacheResolved implements \JsonSerializable
18
{
19
    /**
20
     * @var string
21
     */
22
    private $path;
23
24
    /**
25
     * @var string[]
26
     */
27
    private $uris;
28
29
    /**
30
     * @param string        $path
31
     * @param string[]|null $uris
32
     */
33
    public function __construct(string $path, array $uris)
34
    {
35
        $this->path = $path;
36
        $this->uris = $uris;
37
    }
38
39
    /**
40
     * @return string
41
     */
42
    public function getPath(): string
43
    {
44
        return $this->path;
45
    }
46
47
    /**
48
     * @return string[]
49
     */
50
    public function getUris(): array
51
    {
52
        return $this->uris;
53
    }
54
55
    /**
56
     * {@inheritdoc}
57
     */
58
    public function jsonSerialize(): array
59
    {
60
        return ['path' => $this->path, 'uris' => $this->uris];
61
    }
62
63
    /**
64
     * @param string $json
65
     *
66
     * @return self
67
     */
68
    public static function jsonDeserialize(string $json): self
69
    {
70
        $data = JSON::decode($json);
71
72
        if (empty($data['path'])) {
73
            throw new LogicException('The message does not contain "path" but it is required.');
74
        }
75
76
        if (empty($data['uris'])) {
77
            throw new LogicException('The message uris must not be empty array.');
78
        }
79
80
        return new static($data['path'], $data['uris']);
81
    }
82
}
83