RelatedQueriesSearch::getToken()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php declare(strict_types=1);
2
3
namespace GSoares\GoogleTrends\Search;
4
5
use GSoares\GoogleTrends\Error\GoogleTrendsException;
6
use GSoares\GoogleTrends\Result\RelatedResult;
7
use GSoares\GoogleTrends\Result\ExploreResultCollection;
8
9
/**
10
 * @author Gabriel Felipe Soares <[email protected]>
11
 */
12
class RelatedQueriesSearch extends AbstractRelatedSearch
13
{
14 5
    protected function getKeywordType(): string
15
    {
16 5
        return 'QUERY';
17
    }
18
19
    /**
20
     * @inheritDoc
21
     */
22 4
    protected function createResult(array $data): RelatedResult
23
    {
24 4
        if (!isset($data['query'], $data['value'], $data['link'])) {
25 1
            throw new GoogleTrendsException(
26 1
                sprintf(
27 1
                    'Google ranked list does not contain all keys. Only has: %s',
28 1
                    implode(', ', array_keys($data))
29
                )
30
            );
31
        }
32
33 3
        return new RelatedResult(
34 3
            (string)$data['query'],
35 3
            (bool)($data['hasData'] ?? false),
36 3
            (int)$data['value'],
37 3
            self::TRENDS_URL . (string)$data['link'],
38 3
            $this->isRisingMetric($data) ? 'RISING' : 'TOP'
39
        );
40
    }
41
42
    /**
43
     * @inheritDoc
44
     */
45 5
    protected function getToken(ExploreResultCollection $resultCollection): string
46
    {
47 5
        return $resultCollection->getRelatedQueriesResult()->getToken();
48
    }
49
}
50