CacheResolved::getPath()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
nc 1
nop 0
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[]|null $uris
31
     */
32
    public function __construct(string $path, array $uris)
33
    {
34
        $this->path = $path;
35
        $this->uris = $uris;
36
    }
37
38
    public function getPath(): string
39
    {
40
        return $this->path;
41
    }
42
43
    /**
44
     * @return string[]
45
     */
46
    public function getUris(): array
47
    {
48
        return $this->uris;
49
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54
    public function jsonSerialize(): array
55
    {
56
        return ['path' => $this->path, 'uris' => $this->uris];
57
    }
58
59
    public static function jsonDeserialize(string $json): self
60
    {
61
        $data = JSON::decode($json);
62
63
        if (empty($data['path'])) {
64
            throw new LogicException('The message does not contain "path" but it is required.');
65
        }
66
67
        if (empty($data['uris'])) {
68
            throw new LogicException('The message uris must not be empty array.');
69
        }
70
71
        return new static($data['path'], $data['uris']);
72
    }
73
}
74