Completed
Push — master ( 49f631...00219d )
by Frank
03:48
created

Route::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 2
crap 2
1
<?php
2
declare(strict_types=1);
3
4
/*
5
 * This file is part of the package neoblack/free-at-home-api.
6
 *
7
 * For the full copyright and license information, please read the
8
 * LICENSE file that was distributed with this source code.
9
 */
10
11
namespace NeoBlack\FreeAtHomeApi\Entity;
12
13
use NeoBlack\FreeAtHomeApi\Exception\MethodNotAllowedException;
14
15
class Route
16
{
17
    public const METHOD_GET = 'GET';
18
    public const METHOD_POST = 'POST';
19
    public const METHOD_PUT = 'PUT';
20
    public const METHOD_DELETE = 'DELETE';
21
22
    private $allowedMethods = [
23
        self::METHOD_GET,
24
        self::METHOD_POST,
25
        self::METHOD_PUT,
26
        self::METHOD_DELETE
27
    ];
28
29
    protected $path;
30
    protected $method;
31
32 10
    public function __construct(string $path, string $method)
33
    {
34 10
        if (!\in_array($method, $this->allowedMethods, true)) {
35 5
            throw new MethodNotAllowedException('The method "' . $method . '" is not allowed', 1536352833);
36
        }
37 5
        $this->path = $path;
38 5
        $this->method = $method;
39 5
    }
40
41
    /**
42
     * @return string
43
     */
44 5
    public function getPath(): string
45
    {
46 5
        return $this->path;
47
    }
48
49
    /**
50
     * @return string
51
     */
52 5
    public function getMethod(): string
53
    {
54 5
        return $this->method;
55
    }
56
}
57