Places::validateExtension()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 3
eloc 4
nc 3
nop 1
1
<?php
2
3
/**
4
 * This file is a part of nekland places api package
5
 *
6
 * (c) Nekland <[email protected]>
7
 *
8
 * For the full license, take a look to the LICENSE file
9
 * on the root directory of this project
10
 */
11
12
namespace Nekland\PlacesApi\Api;
13
14
15
use Doctrine\Instantiator\Exception\InvalidArgumentException;
16
use Nekland\BaseApi\Api\AbstractApi;
17
18
/**
19
 * Class Places
20
 *
21
 * Return a place resource
22
 */
23
class Places extends AbstractApi
24
{
25
    const URL = 'details/json';
26
    private $validExtensions = ['review_summary'];
27
28
    /**
29
     * To see a list of supported languages, please checkout https://developers.google.com/maps/faq#languagesupport
30
     *
31
     * @param string $id
32
     * @param array  $extensions
33
     * @param string  $language
34
     * @return array
35
     */
36
    public function getPlaceById($id, array $extensions = [], $language = null)
37
    {
38
        $this->validateExtension($extensions);
39
        $extensions = implode(',', $extensions);
40
41
        $body = array_merge(
42
            ['placeid' => $id],
43
            !empty($extensions) ? ['extensions' => $extensions] : [],
44
            null !== $language ? ['language' => $language] : []
45
        );
46
47
        return $this->get(self::URL, $body);
48
    }
49
50
    /**
51
     * @param array $extensions
52
     */
53
    private function validateExtension(array $extensions)
54
    {
55
        foreach ($extensions as $extension) {
56
            if (!in_array($extension, $this->validExtensions)) {
57
                throw new \InvalidArgumentException(sprintf('The extensions can only be one of "%s"', implode(',', $this->validExtensions)));
58
            }
59
        }
60
    }
61
}
62