Completed
Push — master ( ba0dc9...449151 )
by John
01:49
created

EndpointFactory   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 38
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getEndpoint() 0 15 3
A getSupportedEndpoints() 0 3 1
1
<?php
2
namespace GeoPhone\EndpointFactory;
3
4
use GeoPhone\Endpoints\v1\PhoneNumbers;
5
use GeoPhone\Models\GeoPhone;
6
use LunixREST\Endpoint\Endpoint;
7
use LunixREST\Endpoint\Exceptions\UnknownEndpointException;
8
9
class EndpointFactory implements \LunixREST\Endpoint\EndpointFactory {
10
11
    protected $geoPhone;
12
13
    public function __construct(GeoPhone $geoPhone) {
14
        $this->geoPhone = $geoPhone;
15
    }
16
17
    /**
18
     * @param string $name
19
     * @param string $version
20
     * @return Endpoint
21
     * @throws UnknownEndpointException
22
     */
23
    public function getEndpoint(string $name, string $version): Endpoint {
24
        switch($version) {
25
            case "1":
26
                switch (strtolower($name)) {
27
                    case "phonenumbers":
28
                        return new PhoneNumbers($this->geoPhone);
29
                        break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
30
                    default:
31
                        throw new UnknownEndpointException("Endpoint: $name not supported");
32
                }
33
                break;
34
            default:
35
                throw new UnknownEndpointException("Version: $version not support");
36
        }
37
    }
38
39
    /**
40
     * @param string $version
41
     * @return string[]
42
     */
43
    public function getSupportedEndpoints(string $version): array {
44
        return ["phonenumbers"];
45
    }
46
}
47