EndpointFactory::getEndpoint()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 10
nc 3
nop 2
dl 0
loc 14
rs 9.4285
c 0
b 0
f 0
1
<?php
2
namespace GeoPhone\EndpointFactory;
3
4
use GeoPhone\Endpoints\v1\PhoneNumbers;
5
use GeoPhone\Models\GeoPhone;
6
use LunixREST\Server\Router\Endpoint\Endpoint;
7
use LunixREST\Server\Router\EndpointFactory\Exceptions\UnableToCreateEndpointException;
8
use LunixREST\Server\Router\EndpointFactory\Exceptions\UnknownEndpointException;
9
10
class EndpointFactory implements \LunixREST\Server\Router\EndpointFactory\EndpointFactory
11
{
12
13
    protected $geoPhone;
14
15
    public function __construct(GeoPhone $geoPhone)
16
    {
17
        $this->geoPhone = $geoPhone;
18
    }
19
20
    /**
21
     * @param string $name
22
     * @param string $version
23
     * @return Endpoint
24
     * @throws UnableToCreateEndpointException
25
     * @throws UnknownEndpointException
26
     */
27
    public function getEndpoint(string $name, string $version): Endpoint
28
    {
29
        switch ($version) {
30
            case "1":
0 ignored issues
show
Coding Style introduced by
There must be a comment when fall-through is intentional in a non-empty case body
Loading history...
31
                switch (strtolower($name)) {
32
                    case "phonenumbers":
33
                        return new PhoneNumbers($this->geoPhone);
34
                    default:
35
                        throw new UnknownEndpointException("Endpoint: $name not supported");
36
                }
37
            default:
38
                throw new UnknownEndpointException("Version: $version not support");
39
        }
40
    }
41
42
    /**
43
     * @param string $version
44
     * @return string[]
45
     */
46
    public function getSupportedEndpoints(string $version): array
47
    {
48
        return ["phonenumbers"];
49
    }
50
}
51