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

DirectionService   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 4
dl 29
loc 29
ccs 0
cts 19
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 7 7 1
A route() 15 15 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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