Search::textSearch()   B
last analyzed

Complexity

Conditions 5
Paths 2

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 16
rs 8.8571
cc 5
eloc 9
nc 2
nop 2
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
use Nekland\BaseApi\Api\AbstractApi;
15
use Nekland\PlacesApi\Iterator\SearchIterator;
16
17
/**
18
 * Class Search
19
 *
20
 * This class ask for Google Places API for search.
21
 * You can learn more about "others" parameters here: https://developers.google.com/places/documentation/search
22
 */
23
class Search extends AbstractApi
24
{
25
    /**
26
     * @param string $location Format: latitude,longitude
27
     * @param string $radius   Meters for search from the location point (max 50 000 meters)
28
     * @param array  $other    More parameters, see google documentation
29
     * @return array
30
     */
31 View Code Duplication
    public function searchLocation($location, $radius, array $other = [])
0 ignored issues
show
Duplication introduced by
This method 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...
32
    {
33
        $body = array_merge(
34
            ['location' => $location, 'radius' => $radius],
35
            $other
36
        );
37
38
        return $this->searchWithBody($body);
39
    }
40
41
    /**
42
     * All required information should be in an array
43
     *
44
     * @param array $body
45
     * @return array
46
     */
47
    public function searchWithBody(array $body)
48
    {
49
        return $this->get('nearbysearch/json', $body);
50
    }
51
52
    /**
53
     * @param string $location Format: latitude,longitude
54
     * @param string $radius   Meters for search from the location point (max 50 000 meters)
55
     * @param array  $other    More parameters, see google documentation
56
     * @return SearchIterator
57
     */
58 View Code Duplication
    public function getSearchIterator($location, $radius, array $other = [])
0 ignored issues
show
Duplication introduced by
This method 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...
59
    {
60
        $body = array_merge(
61
            ['location' => $location, 'radius' => $radius],
62
            $other
63
        );
64
65
        return new SearchIterator($this, $body);
66
    }
67
68
    /**
69
     * @param string $text
70
     * @param array  $others
71
     * @return array
72
     */
73
    public function textSearch($text, array $others = [])
74
    {
75
        if (
76
            !empty($others['location']) && empty($others['radius']) ||
77
            !empty($others['radius']) && empty($others['location'])
78
        ) {
79
            throw new \InvalidArgumentException('If you specify location or radius, you have to specify both');
80
        }
81
82
        $body = array_merge(
83
            ['query' => $text],
84
            $others
85
        );
86
87
        return $this->get('textsearch/json', $body);
88
    }
89
}
90