1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace DH\NavigationBundle\Provider\Here\Routing; |
4
|
|
|
|
5
|
|
|
use DH\NavigationBundle\Contract\Routing\RoutingResponseInterface; |
6
|
|
|
use DH\NavigationBundle\Model\Routing\Leg; |
7
|
|
|
use DH\NavigationBundle\Model\Routing\Route; |
8
|
|
|
use DH\NavigationBundle\Model\Routing\Step; |
9
|
|
|
use DH\NavigationBundle\Model\Routing\Summary; |
10
|
|
|
use Psr\Http\Message\ResponseInterface; |
11
|
|
|
|
12
|
|
|
class RoutingResponse implements RoutingResponseInterface |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @var string |
16
|
|
|
*/ |
17
|
|
|
private $status; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var \stdClass |
21
|
|
|
*/ |
22
|
|
|
private $responseObject; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var array |
26
|
|
|
*/ |
27
|
|
|
private $routes; |
28
|
|
|
|
29
|
|
|
public function __construct(ResponseInterface $response) |
30
|
|
|
{ |
31
|
|
|
$responseObject = json_decode($response->getBody()->getContents()); |
32
|
|
|
$this->responseObject = $responseObject; |
33
|
|
|
$this->status = $response->getReasonPhrase(); |
34
|
|
|
|
35
|
|
|
$this->initialize(); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @return mixed |
40
|
|
|
*/ |
41
|
|
|
public function getStatus(): string |
42
|
|
|
{ |
43
|
|
|
return $this->status; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @return \stdClass |
48
|
|
|
*/ |
49
|
|
|
public function getResponseObject(): \stdClass |
50
|
|
|
{ |
51
|
|
|
return $this->responseObject; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
private function initialize(): void |
55
|
|
|
{ |
56
|
|
|
// routes, waypoints, legs, steps |
57
|
|
|
foreach ($this->responseObject->response->route as $routeElement) { |
58
|
|
|
$legs = []; |
59
|
|
|
|
60
|
|
|
foreach ($routeElement->leg as $legElement) { |
61
|
|
|
$steps = []; |
62
|
|
|
foreach ($legElement->maneuver as $stepElement) { |
63
|
|
|
$steps[] = new Step([ |
|
|
|
|
64
|
|
|
'position' => (array) $stepElement->position, |
65
|
|
|
'instruction' => $stepElement->instruction, |
66
|
|
|
'duration' => $stepElement->travelTime, |
67
|
|
|
'distance' => $stepElement->length, |
68
|
|
|
]); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
$legs[] = new Leg([ |
72
|
|
|
'start' => (array) $legElement->start->originalPosition, |
73
|
|
|
'end' => (array) $legElement->end->originalPosition, |
74
|
|
|
'duration' => $legElement->travelTime, |
75
|
|
|
'distance' => $legElement->length, |
76
|
|
|
'steps' => $steps, |
77
|
|
|
]); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
$this->routes[] = new Route([ |
81
|
|
|
'legs' => $legs, |
82
|
|
|
'summary' => new Summary((array) $routeElement->summary), |
83
|
|
|
]); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @return array |
89
|
|
|
*/ |
90
|
|
|
public function getRoutes(): array |
91
|
|
|
{ |
92
|
|
|
return $this->routes; |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.