Method   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
c 1
b 0
f 0
dl 0
loc 66
ccs 0
cts 28
cp 0
rs 10
wmc 13

12 Methods

Rating   Name   Duplication   Size   Complexity  
A ensureIsValidHttpMethod() 0 5 2
A equals() 0 3 1
A delete() 0 3 1
A asString() 0 3 1
A post() 0 3 1
A put() 0 3 1
A patch() 0 3 1
A head() 0 3 1
A options() 0 3 1
A __construct() 0 4 1
A fetch() 0 3 1
A get() 0 3 1
1
<?php
2
/**
3
 * This file is part of Phiremock.
4
 *
5
 * Phiremock is free software: you can redistribute it and/or modify
6
 * it under the terms of the GNU Lesser General Public License as published by
7
 * the Free Software Foundation, either version 3 of the License, or
8
 * (at your option) any later version.
9
 *
10
 * Phiremock is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with Phiremock.  If not, see <http://www.gnu.org/licenses/>.
17
 */
18
19
namespace Mcustiel\Phiremock\Domain\Http;
20
21
class Method
22
{
23
    /** @var string * */
24
    private $method;
25
26
    public function __construct(string $method)
27
    {
28
        $this->ensureIsValidHttpMethod($method);
29
        $this->method = strtolower($method);
30
    }
31
32
    public static function get(): self
33
    {
34
        return new self(MethodsEnum::GET);
35
    }
36
37
    public static function post(): self
38
    {
39
        return new self(MethodsEnum::POST);
40
    }
41
42
    public static function put(): self
43
    {
44
        return new self(MethodsEnum::PUT);
45
    }
46
47
    public static function delete(): self
48
    {
49
        return new self(MethodsEnum::DELETE);
50
    }
51
52
    public static function fetch(): self
53
    {
54
        return new self(MethodsEnum::FETCH);
55
    }
56
57
    public static function options(): self
58
    {
59
        return new self(MethodsEnum::OPTIONS);
60
    }
61
62
    public static function patch(): self
63
    {
64
        return new self(MethodsEnum::PATCH);
65
    }
66
67
    public static function head(): self
68
    {
69
        return new self(MethodsEnum::HEAD);
70
    }
71
72
    public function asString(): string
73
    {
74
        return $this->method;
75
    }
76
77
    public function equals(self $other): bool
78
    {
79
        return $this->asString() === $other->asString();
80
    }
81
82
    private function ensureIsValidHttpMethod(string $method): void
83
    {
84
        var_export('ensurer');
85
        if (!MethodsEnum::isValid($method)) {
86
            throw new \InvalidArgumentException(sprintf('Invalid http method: %s', var_export($method, true)));
87
        }
88
    }
89
}
90