NavigationManager::createDistanceMatrixQuery()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 9
rs 10
1
<?php
2
3
namespace DH\NavigationBundle;
4
5
use DH\NavigationBundle\Contract\DistanceMatrix\DistanceMatrixQueryInterface;
6
use DH\NavigationBundle\Contract\Routing\RoutingQueryInterface;
7
use DH\NavigationBundle\Exception\UnsupportedFeatureException;
8
use DH\NavigationBundle\Provider\ProviderAggregator;
9
use DH\NavigationBundle\Provider\ProviderInterface;
10
11
class NavigationManager
12
{
13
    /**
14
     * @var ProviderAggregator
15
     */
16
    private $providerAggregator;
17
18
    public function __construct(ProviderAggregator $providerAggregator)
19
    {
20
        $this->providerAggregator = $providerAggregator;
21
    }
22
23
    /**
24
     * Sets the default provider to use.
25
     *
26
     * @return NavigationManager
27
     */
28
    public function using(string $name): self
29
    {
30
        $this->providerAggregator->using($name);
31
32
        return $this;
33
    }
34
35
    /**
36
     * @throws UnsupportedFeatureException
37
     */
38
    public function createDistanceMatrixQuery(): DistanceMatrixQueryInterface
39
    {
40
        $provider = $this->providerAggregator->getProvider();
41
42
        if (method_exists($provider, 'createDistanceMatrixQuery')) {
43
            return $provider->createDistanceMatrixQuery();
44
        }
45
46
        throw new UnsupportedFeatureException(sprintf('Distance Matrix is not supported by "%s" provider.', $provider->getName()));
47
    }
48
49
    /**
50
     * @throws UnsupportedFeatureException
51
     */
52
    public function createRoutingQuery(): RoutingQueryInterface
53
    {
54
        $provider = $this->providerAggregator->getProvider();
55
56
        if (method_exists($provider, 'createRoutingQuery')) {
57
            return $provider->createRoutingQuery();
58
        }
59
60
        throw new UnsupportedFeatureException(sprintf('Routing is not supported by "%s" provider.', $provider->getName()));
61
    }
62
63
    public function getProvider(?string $name = null): ProviderInterface
64
    {
65
        return $this->providerAggregator->getProvider($name);
66
    }
67
68
    public function getProviders(): array
69
    {
70
        return $this->providerAggregator->getProviders();
71
    }
72
73
    public function getProviderAggregator(): ProviderAggregator
74
    {
75
        return $this->providerAggregator;
76
    }
77
}
78