Router   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 20
rs 10
c 0
b 0
f 0
ccs 4
cts 4
cp 1
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A get() 0 6 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\Service;
12
13
use NeoBlack\FreeAtHomeApi\Entity\Route;
14
use NeoBlack\FreeAtHomeApi\Exception\UnknownRouteException;
15
16
class Router
17
{
18
    public const DEVICES_GET = 'DEVICES_GET';
19
    public const DEVICE_GET = 'DEVICE_GET';
20
    public const DEVICE_UPDATE = 'DEVICE_UPDATE';
21
    public const DEVICE_DELETE = 'DEVICE_DELETE';
22
23
    private $methods = [
24 2
        self::DEVICES_GET => ['/devices', Route::METHOD_GET],
25
        self::DEVICE_GET => ['/device/{id}', Route::METHOD_GET],
26 2
        self::DEVICE_UPDATE => ['/device/{id}', Route::METHOD_PUT],
27 1
        self::DEVICE_DELETE => ['/device/{id}', Route::METHOD_DELETE],
28
    ];
29 1
30
    public function get(string $identifier, array $routeParameter = []): Route
31
    {
32
        if (!isset($this->methods[$identifier])) {
33
            throw new UnknownRouteException('The route with identifier "' . $identifier . '" is unknown', 1536351904);
34
        }
35
        return new Route($this->methods[$identifier][0], $this->methods[$identifier][1], $routeParameter);
36
    }
37
}
38