Completed
Push — master ( 9df105...b9a551 )
by Arthur
02:20
created

PlaceClient::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 4
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\Place\Hydrator\PlaceHydrator;
8
use Arthem\GooglePlaces\Domain\Place\Exception\PlaceNotFoundException;
9
use GuzzleHttp\ClientInterface;
10
11
class PlaceClient extends Client implements PlaceClientInterface
12
{
13
    /**
14
     * {@inheritdoc}
15
     */
16
    protected $apiUrl = 'https://maps.googleapis.com/maps/api/place';
17
18
    /**
19
     * @var PlaceHydrator
20
     */
21
    private $placeHydrator;
22
23
    public function __construct(ClientInterface $httpClient, $decoder, $apiKey, PlaceHydrator $placeHydrator)
24
    {
25
        parent::__construct($httpClient, $decoder, $apiKey);
26
        $this->placeHydrator = $placeHydrator;
27
    }
28
29
    /**
30
     * {@inheritdoc}
31
     */
32
    public function nearbysearch(array $params)
33
    {
34
        $response = $this->request('GET', '/nearbysearch', $params);
35
36
        return $this->placeHydrator->hydratePlaces($response['results']);
37
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42
    public function details(array $params)
43
    {
44
        $response = $this->request('GET', '/details', $params);
45
        $place = $this->placeHydrator->hydratePlace($response['result']);
46
47
        if (null === $place) {
48
            throw new PlaceNotFoundException(sprintf('The place was not found'));
49
        }
50
51
        return $place;
52
    }
53
}
54