BindVolume::isReadOnly()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace TheAentMachine\Service\Volume;
4
5
use TheAentMachine\Service\Enum\VolumeTypeEnum;
6
7
class BindVolume extends Volume
8
{
9
    /** @var string */
10
    private $target;
11
    /** @var bool */
12
    private $readOnly;
13
14
    public function __construct(string $source, string $target, bool $readOnly = false, ?string $comment = null)
15
    {
16
        parent::__construct($source, $comment);
17
        $this->target = $target;
18
        $this->readOnly = $readOnly;
19
        $this->comment = $comment;
20
    }
21
22
    public function getType(): string
23
    {
24
        return VolumeTypeEnum::BIND_VOLUME;
25
    }
26
27
    /**
28
     * @return string
29
     */
30
    public function getSource(): string
31
    {
32
        return $this->source;
33
    }
34
35
    public function getTarget(): string
36
    {
37
        return $this->target;
38
    }
39
40
    public function isReadOnly(): bool
41
    {
42
        return $this->readOnly;
43
    }
44
45
    /**
46
     * Specify data which should be serialized to JSON
47
     * @link http://php.net/manual/en/jsonserializable.jsonserialize.php
48
     * @return array data which can be serialized by <b>json_encode</b>,
49
     * which is a value of any type other than a resource.
50
     * @since 5.4.0
51
     */
52
    public function jsonSerialize(): array
53
    {
54
        return array_filter([
55
            'type' => $this->getType(),
56
            'source' => $this->source,
57
            'target' => $this->target,
58
            'readOnly' => $this->readOnly,
59
            'comment' => $this->comment
60
        ], function ($v) {
61
            return null !== $v;
62
        });
63
    }
64
}
65