Passed
Push — master ( 0ab104...bfda64 )
by Jeroen
03:26
created

Domain/MediaItemImport/Method.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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
    /**
20
     * @param string $method
21
     */
22 View Code Duplication
    private function __construct(string $method)
1 ignored issue
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
23
    {
24
        if (!in_array($method, self::POSSIBLE_VALUES, true)) {
25
            throw new \InvalidArgumentException(
26
                'Invalid value for possible MediaItemImport method. Possible values; ' . implode(',', self::POSSIBLE_VALUES)
27
            );
28
        }
29
30
        $this->method = $method;
31
    }
32
33
    /**
34
     * @param string $method
35
     * @return Method
36
     */
37
    public static function fromString(string $method): Method
38
    {
39
        return new self($method);
40
    }
41
42
    /**
43
     * @return string
44
     */
45
    public function __toString(): string
46
    {
47
        return $this->method;
48
    }
49
50
    /**
51
     * @param Method $method
52
     * @return bool
53
     */
54
    public function equals(Method $method): bool
55
    {
56
        return $method->method === $this->method;
57
    }
58
59
    /**
60
     * @return Method
61
     */
62
    public static function copy(): Method
63
    {
64
        return new self(self::COPY);
65
    }
66
67
    /**
68
     * @return bool
69
     */
70
    public function isCopy(): bool
71
    {
72
        return $this->equals(self::copy());
73
    }
74
75
    /**
76
     * @return Method
77
     */
78
    public static function move(): Method
79
    {
80
        return new self(self::MOVE);
81
    }
82
83
    /**
84
     * @return bool
85
     */
86
    public function isMove(): bool
87
    {
88
        return $this->equals(self::move());
89
    }
90
91
    /**
92
     * @return Method
93
     */
94
    public static function download(): Method
95
    {
96
        return new self(self::DOWNLOAD);
97
    }
98
99
    /**
100
     * @return bool
101
     */
102
    public function isDownload(): bool
103
    {
104
        return $this->equals(self::download());
105
    }
106
107
    /**
108
     * @return string
109
     */
110
    public function getMethod(): string
111
    {
112
        return $this->method;
113
    }
114
}
115