ResolveCache   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 2
dl 0
loc 68
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getPath() 0 4 1
A getFilters() 0 4 1
A isForce() 0 4 1
A jsonSerialize() 0 4 1
A jsonDeserialize() 0 14 4
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 ResolveCache implements \JsonSerializable
18
{
19
    /**
20
     * @var string
21
     */
22
    private $path;
23
24
    /**
25
     * @var array|\string[]|null
26
     */
27
    private $filters;
28
29
    /**
30
     * @var bool
31
     */
32
    private $force;
33
34
    /**
35
     * @param string[]|null $filters
36
     */
37
    public function __construct(string $path, array $filters = null, bool $force = false)
38
    {
39
        $this->path = $path;
40
        $this->filters = $filters;
41
        $this->force = $force;
42
    }
43
44
    public function getPath(): string
45
    {
46
        return $this->path;
47
    }
48
49
    /**
50
     * @return \string[]|null
51
     */
52
    public function getFilters()
53
    {
54
        return $this->filters;
55
    }
56
57
    public function isForce(): bool
58
    {
59
        return $this->force;
60
    }
61
62
    /**
63
     * {@inheritdoc}
64
     */
65
    public function jsonSerialize(): array
66
    {
67
        return ['path' => $this->path, 'filters' => $this->filters, 'force' => $this->force];
68
    }
69
70
    public static function jsonDeserialize(string $json): self
71
    {
72
        $data = array_replace(['path' => null, 'filters' => null, 'force' => false], JSON::decode($json));
73
74
        if (!$data['path']) {
75
            throw new LogicException('The message does not contain "path" but it is required.');
76
        }
77
78
        if (!(null === $data['filters'] || \is_array($data['filters']))) {
79
            throw new LogicException('The message filters could be either null or array.');
80
        }
81
82
        return new static($data['path'], $data['filters'], $data['force']);
83
    }
84
}
85