Method   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 109
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 0
dl 0
loc 109
ccs 26
cts 26
cp 1
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 2
A post() 0 4 1
A put() 0 4 1
A patch() 0 4 1
A delete() 0 4 1
A get() 0 4 1
A getValue() 0 4 1
A getPossibleValues() 0 10 1
1
<?php
2
3
declare(strict_types = 1);
4
5
/*
6
 * This file is part of the FiveLab Resource package
7
 *
8
 * (c) FiveLab
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code
12
 */
13
14
namespace FiveLab\Component\Resource\Resource\Action;
15
16
/**
17
 * The value object for store method.
18
 *
19
 * @author Vitaliy Zhuk <[email protected]>
20
 */
21
class Method
22
{
23
    public const POST   = 'POST';
24
    public const PUT    = 'PUT';
25
    public const PATCH  = 'PATCH';
26
    public const DELETE = 'DELETE';
27
    public const GET    = 'GET';
28
29
    /**
30
     * @var string
31
     */
32
    private $value;
33
34
    /**
35
     * Constructor.
36
     *
37
     * @param string $value
38
     *
39
     * @throws \InvalidArgumentException
40
     */
41 12
    public function __construct(string $value)
42
    {
43 12
        if (!\in_array($value, self::getPossibleValues(), true)) {
44 1
            throw new \InvalidArgumentException(\sprintf(
45 1
                'Invalid method "%s". Available methods: "%s".',
46 1
                $value,
47 1
                \implode('", "', self::getPossibleValues())
48
            ));
49
        }
50
51 11
        $this->value = $value;
52 11
    }
53
54
    /**
55
     * Create POST method
56
     *
57
     * @return Method
58
     */
59 7
    public static function post(): Method
60
    {
61 7
        return new self(self::POST);
62
    }
63
64
    /**
65
     * Create PUT method
66
     *
67
     * @return Method
68
     */
69 2
    public static function put(): Method
70
    {
71 2
        return new self(self::PUT);
72
    }
73
74
    /**
75
     * Create PATCH method
76
     *
77
     * @return Method
78
     */
79 1
    public static function patch(): Method
80
    {
81 1
        return new self(self::PATCH);
82
    }
83
84
    /**
85
     * Create DELETE method
86
     *
87
     * @return Method
88
     */
89 1
    public static function delete(): Method
90
    {
91 1
        return new self(self::DELETE);
92
    }
93
94
    /**
95
     * Create GET method
96
     *
97
     * @return Method
98
     */
99 1
    public static function get(): Method
100
    {
101 1
        return new self(self::GET);
102
    }
103
104
    /**
105
     * Get the value of method
106
     *
107
     * @return string
108
     */
109 5
    public function getValue(): string
110
    {
111 5
        return $this->value;
112
    }
113
114
    /**
115
     * Get the possible values of action method
116
     *
117
     * @return array
118
     */
119 13
    public static function getPossibleValues(): array
120
    {
121
        return [
122 13
            self::POST,
123 13
            self::PUT,
124 13
            self::PATCH,
125 13
            self::DELETE,
126 13
            self::GET,
127
        ];
128
    }
129
}
130