Method::fromString()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Backend\Modules\MediaLibraryImporter\Domain\MediaItemImport;
4
5
final class Method
6
{
7
    const COPY = 'copy';
8
    const DOWNLOAD = 'download';
9
    const MOVE = 'move';
10
    const POSSIBLE_VALUES = [
11
        self::COPY,
12
        self::DOWNLOAD,
13
        self::MOVE
14
    ];
15
16
    /** @var string */
17
    private $method;
18
19
    private function __construct(string $method)
20
    {
21
        if (!in_array($method, self::POSSIBLE_VALUES, true)) {
22
            throw new \InvalidArgumentException(
23
                'Invalid value for possible MediaItemImport method. Possible values; ' . implode(',', self::POSSIBLE_VALUES)
24
            );
25
        }
26
27
        $this->method = $method;
28
    }
29
30
    public static function fromString(string $method): Method
31
    {
32
        return new self($method);
33
    }
34
35
    public function __toString(): string
36
    {
37
        return $this->method;
38
    }
39
40
    public function equals(Method $method): bool
41
    {
42
        return $method->method === $this->method;
43
    }
44
45
    public static function copy(): Method
46
    {
47
        return new self(self::COPY);
48
    }
49
50
    public function isCopy(): bool
51
    {
52
        return $this->equals(self::copy());
53
    }
54
55
    public static function move(): Method
56
    {
57
        return new self(self::MOVE);
58
    }
59
60
    public function isMove(): bool
61
    {
62
        return $this->equals(self::move());
63
    }
64
65
    public static function download(): Method
66
    {
67
        return new self(self::DOWNLOAD);
68
    }
69
70
    public function isDownload(): bool
71
    {
72
        return $this->equals(self::download());
73
    }
74
75
    public function getMethod(): string
76
    {
77
        return $this->method;
78
    }
79
}
80