Completed
Pull Request — master (#1)
by Arthur
02:19
created

PlaceClient   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 4
Bugs 0 Features 2
Metric Value
c 4
b 0
f 2
dl 0
loc 57
wmc 5
lcom 1
cbo 3
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A nearbysearch() 0 6 1
A textsearch() 0 6 1
A details() 0 11 2
1
<?php
2
3
namespace Arthem\GoogleApi\Infrastructure\Place;
4
5
use Arthem\GoogleApi\Domain\Place\Client\PlaceClientInterface;
6
use Arthem\GoogleApi\Infrastructure\Client\Client;
7
use Arthem\GoogleApi\Infrastructure\Client\Decoder\DecoderInterface;
8
use Arthem\GoogleApi\Infrastructure\Place\Hydrator\PlaceHydrator;
9
use Arthem\GooglePlaces\Domain\Place\Exception\PlaceNotFoundException;
10
use GuzzleHttp\ClientInterface;
11
12
class PlaceClient extends Client implements PlaceClientInterface
13
{
14
    /**
15
     * {@inheritdoc}
16
     */
17
    protected $apiUrl = 'https://maps.googleapis.com/maps/api/place';
18
19
    /**
20
     * @var PlaceHydrator
21
     */
22
    private $placeHydrator;
23
24
    public function __construct(
25
        ClientInterface $httpClient,
26
        DecoderInterface $decoder,
27
        $apiKey,
28
        PlaceHydrator $placeHydrator
29
    ) {
30
        parent::__construct($httpClient, $decoder, $apiKey);
31
        $this->placeHydrator = $placeHydrator;
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37
    public function nearbysearch(array $params)
38
    {
39
        $response = $this->request('GET', '/nearbysearch', $params);
40
41
        return $this->placeHydrator->hydratePlaces($response['results']);
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47
    public function textsearch(array $params)
48
    {
49
        $response = $this->request('GET', '/textsearch', $params);
50
51
        return $this->placeHydrator->hydratePlaces($response['results']);
52
    }
53
54
    /**
55
     * {@inheritdoc}
56
     */
57
    public function details(array $params)
58
    {
59
        $response = $this->request('GET', '/details', $params);
60
        $place = $this->placeHydrator->hydratePlace($response['result']);
61
62
        if (null === $place) {
63
            throw new PlaceNotFoundException(sprintf('The place was not found'));
64
        }
65
66
        return $place;
67
    }
68
}
69