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

PlaceClient   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A nearbysearch() 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\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