Completed
Push — master ( 39762b...5dff0a )
by Samuel
12s queued 11s
created

DirectionService::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 7
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 7
loc 7
ccs 0
cts 7
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 3
crap 2
1
<?php
2
3
/*
4
 * This file is part of the Ivory Google Map package.
5
 *
6
 * (c) Eric GELOEN <[email protected]>
7
 *
8
 * For the full copyright and license information, please read the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Ivory\GoogleMap\Service\Direction;
13
14
use Http\Client\HttpClient;
15
use Http\Message\MessageFactory;
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
23
/**
24
 * @author GeLo <[email protected]>
25
 */
26 View Code Duplication
class DirectionService extends AbstractSerializableService
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
27
{
28
    public function __construct(
29
        HttpClient $client,
30
        MessageFactory $messageFactory,
31
        SerializerInterface $serializer = null
32
    ) {
33
        parent::__construct('https://maps.googleapis.com/maps/api/directions', $client, $messageFactory, $serializer);
34
    }
35
36
    /**
37
     * @return DirectionResponse
38
     */
39
    public function route(DirectionRequestInterface $request)
40
    {
41
        $httpRequest = $this->createRequest($request);
42
        $httpResponse = $this->getClient()->sendRequest($httpRequest);
43
44
        $response = $this->deserialize(
45
            $httpResponse,
46
            DirectionResponse::class,
47
            (new Context())->setNamingStrategy(new SnakeCaseNamingStrategy())
48
        );
49
50
        $response->setRequest($request);
51
52
        return $response;
53
    }
54
}
55