Search   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 1
dl 0
loc 69
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getSearchEngineExtensions() 0 11 1
A getTownCode() 0 10 1
A getUrlRankByKeyword() 0 26 4
A getNaturalSeoResult() 0 4 1
A getSemResult() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * MyPoseo API Bundle
7
 *
8
 * @author Tristan Bessoussa <[email protected]>
9
 */
10
11
namespace Tristanbes\MyPoseoBundle\Api;
12
13
use Tristanbes\MyPoseoBundle\Connection\RestClient;
14
15
/**
16
 * @see http://fr.myposeo.com/nos-api/api-search/
17
 */
18
class Search implements SearchInterface
19
{
20
    private $client;
21
22
    public function __construct(RestClient $client)
23
    {
24
        $this->client = $client;
25
    }
26
27
    public function getSearchEngineExtensions(string $searchEngine, ?int $ttl = null): array
28
    {
29
        $cacheKey = sprintf('%s_locations', $searchEngine);
30
31
        $data = $this->client->get('tool/json', [
32
            'method'       => 'getLocations',
33
            'searchEngine' => $searchEngine,
34
        ], $cacheKey, $ttl);
35
36
        return $data;
37
    }
38
39
    public function getTownCode(string $name, string $country = 'FR'): array
40
    {
41
        $data = $this->client->get('tool/json', [
42
            'method'  => 'getGeoloc',
43
            'country' => $country,
44
            'city'    => $name,
45
        ]);
46
47
        return $data;
48
    }
49
50
    public function getUrlRankByKeyword(string $keyword, string $url, string $searchEngine = 'google', ?string $callbackUrl = null, ?int $geolocId = null, int $location = 13, ?int $maxPage = null): array
51
    {
52
        $options = [];
53
54
        if (null !== $callbackUrl) {
55
            $options['callback'] = $callbackUrl;
56
        }
57
58
        if (null !== $geolocId) {
59
            $options['geolocId'] = $geolocId;
60
        }
61
62
        if (null !== $maxPage) {
63
            $options['maxPage'] = $maxPage;
64
        }
65
66
        $data = $this->client->get('tool/json', array_merge([
67
            'method'       => 'getPosition',
68
            'keyword'      => $keyword,
69
            'url'          => $url,
70
            'searchEngine' => $searchEngine,
71
            'location'     => $location,
72
        ], $options));
73
74
        return $data;
75
    }
76
77
    public function getNaturalSeoResult()
78
    {
79
        throw new \RuntimeException(sprintf('Method "%s" is not implemented.', __METHOD__));
80
    }
81
82
    public function getSemResult()
83
    {
84
        throw new \RuntimeException(sprintf('Method "%s" is not implemented.', __METHOD__));
85
    }
86
}
87