Passed
Push — master ( df2e7d...4ffc8b )
by Gabriel Felipe
01:40 queued 10s
created

getInterestOverTimeResult()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 5
cts 5
cp 1
rs 9.9332
c 0
b 0
f 0
cc 3
nc 3
nop 0
crap 3
1
<?php declare(strict_types=1);
2
3
namespace GSoares\GoogleTrends\Result;
4
5
use GSoares\GoogleTrends\Error\GoogleTrendsException;
6
7
/**
8
 * @author Gabriel Felipe Soares <[email protected]>
9
 */
10
class ExploreResultCollection
11
{
12
    /**
13
     * @var ExploreResult[]
14
     */
15
    public $results;
16
17 14
    public function __construct(ExploreResult ...$terms)
18
    {
19 14
        $this->results = $terms;
20 14
    }
21
22
    /**
23
     * @return RelatedResult[]
24
     */
25 1
    public function getResults(): array
26
    {
27 1
        return $this->results;
28
    }
29
30
    /**
31
     * @return ExploreResult
32
     *
33
     * @throws GoogleTrendsException
34
     */
35 6
    public function getRelatedQueriesResult(): ExploreResult
36
    {
37 6
        foreach ($this->results as $result) {
38 5
            if ($result->isRelatedQueriesSearch()) {
39 5
                return $result;
40
            }
41
        }
42
43 1
        throw new GoogleTrendsException('No explore result available for related queries!');
44
    }
45
46
    /**
47
     * @return ExploreResult
48
     *
49
     * @throws GoogleTrendsException
50
     */
51 6
    public function getRelatedTopicsResult(): ExploreResult
52
    {
53 6
        foreach ($this->results as $result) {
54 5
            if ($result->isRelatedTopicsSearch()) {
55 5
                return $result;
56
            }
57
        }
58
59 1
        throw new GoogleTrendsException('No explore result available for related topics!');
60
    }
61
62
    /**
63
     * @return ExploreResult
64
     *
65
     * @throws GoogleTrendsException
66
     */
67 4
    public function getInterestOverTimeResult(): ExploreResult
68
    {
69 4
        foreach ($this->results as $result) {
70 3
            if ($result->isInterestOverTimeSearch()) {
71 3
                return $result;
72
            }
73
        }
74
75 1
        throw new GoogleTrendsException('No explore result available for interest over time!');
76
    }
77
}
78