RelatedTopicsSearch   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 5
dl 0
loc 38
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getKeywordType() 0 4 1
A createResult() 0 19 3
A getToken() 0 4 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 RelatedTopicsSearch extends AbstractRelatedSearch
13
{
14 3
    protected function getKeywordType(): string
15
    {
16 3
        return 'ENTITY';
17
    }
18
19
    /**
20
     * @inheritDoc
21
     */
22 2
    protected function createResult(array $data): RelatedResult
23
    {
24 2
        if (!isset($data['topic']['title'], $data['topic']['type'], $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 1
        return new RelatedResult(
34 1
            (string)$data['topic']['title'] . ' - ' . $data['topic']['type'],
35 1
            (bool)($data['hasData'] ?? false),
36 1
            (int)$data['value'],
37 1
            self::TRENDS_URL . (string)$data['link'],
38 1
            $this->isRisingMetric($data) ? 'RISING' : 'TOP'
39
        );
40
    }
41
42
    /**
43
     * @inheritDoc
44
     */
45 3
    protected function getToken(ExploreResultCollection $resultCollection): string
46
    {
47 3
        return $resultCollection->getRelatedTopicsResult()->getToken();
48
    }
49
}
50