Passed
Push — feature/v4 ( e5e380...dac4aa )
by Samuel
11:37
created

DirectionService   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
eloc 10
c 0
b 0
f 0
dl 0
loc 24
ccs 0
cts 18
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A route() 0 14 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Ivory Google Map package.
7
 *
8
 * (c) Eric GELOEN <[email protected]>
9
 *
10
 * For the full copyright and license information, please read the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Ivory\GoogleMap\Service\Direction;
15
16
use Ivory\GoogleMap\Service\AbstractSerializableService;
17
use Ivory\GoogleMap\Service\Direction\Request\DirectionRequestInterface;
18
use Ivory\GoogleMap\Service\Direction\Response\DirectionResponse;
19
use Ivory\Serializer\Context\Context;
20
use Ivory\Serializer\Naming\SnakeCaseNamingStrategy;
21
use Ivory\Serializer\SerializerInterface;
22
use Psr\Http\Client\ClientInterface;
23
use Psr\Http\Message\RequestFactoryInterface;
24
25
class DirectionService extends AbstractSerializableService
26
{
27
    public function __construct(
28
        ClientInterface $client,
29
        RequestFactoryInterface $messageFactory,
30
        SerializerInterface $serializer = null
31
    ) {
32
        parent::__construct('https://maps.googleapis.com/maps/api/directions', $client, $messageFactory, $serializer);
33
    }
34
35
    public function route(DirectionRequestInterface $request): DirectionResponse
36
    {
37
        $httpRequest  = $this->createRequest($request);
38
        $httpResponse = $this->getClient()->sendRequest($httpRequest);
39
40
        $response = $this->deserialize(
41
            $httpResponse,
42
            DirectionResponse::class,
43
            (new Context())->setNamingStrategy(new SnakeCaseNamingStrategy())
44
        );
45
46
        $response->setRequest($request);
47
48
        return $response;
49
    }
50
}
51