HttpMethod   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 49
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 2
A toString() 0 3 1
A isValid() 0 3 1
1
<?php
2
3
/*
4
 * Copyright (c) 2011-2015, Celestino Diaz <[email protected]>
5
 *
6
 * Permission is hereby granted, free of charge, to any person obtaining a copy
7
 * of this software and associated documentation files (the "Software"), to deal
8
 * in the Software without restriction, including without limitation the rights
9
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
 * copies of the Software, and to permit persons to whom the Software is
11
 * furnished to do so, subject to the following conditions:
12
 *
13
 * The above copyright notice and this permission notice shall be included in
14
 * all copies or substantial portions of the Software.
15
 *
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
 * THE SOFTWARE.
23
 */
24
25
namespace Brickoo\Component\Http;
26
27
use Brickoo\Component\Http\Exception\InvalidHttpMethodException;
28
use Brickoo\Component\Common\Assert;
29
30
/**
31
 * HttpMethod
32
 *
33
 * Describes a http method.
34
 * @author Celestino Diaz <[email protected]>
35
 */
36
class HttpMethod {
37
38
    /** http methods */
39
    const HEAD = "HEAD";
40
    const OPTIONS = "OPTIONS";
41
    const TRACE = "TRACE";
42
    const CONNECT = "CONNECT";
43
    const GET = "GET";
44
    const POST = "POST";
45
    const PUT = "PUT";
46
    const PATCH = "PATCH";
47
    const DELETE = "DELETE";
48
49
    /** @var string */
50
    private $method;
51
52
    /**
53
     * Class constructor
54
     * @param string $method the http method
55
     * @throws \Brickoo\Component\Http\Exception\InvalidHttpMethodException
56
     */
57 2
    public function __construct($method) {
58 2
        Assert::isString($method);
59
60 2
        if (!$this->isValid($method)) {
61 1
            throw new InvalidHttpMethodException($method);
62
        }
63
64 1
        $this->method = $method;
65 1
    }
66
67
    /**
68
     * Returns the method string representation in uppercase.
69
     * return string the method representation
70
     */
71 1
    public function toString() {
72 1
        return $this->method;
73
    }
74
75
    /**
76
     * Checks if the method is valid.
77
     * @param string $method
78
     * @return boolean result
79
     */
80 2
    private function isValid($method) {
81 2
        return defined("static::".$method);
82
    }
83
84
}
85