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

ExploreResultCollection   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 2
dl 0
loc 68
ccs 20
cts 20
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getResults() 0 4 1
A getRelatedQueriesResult() 0 10 3
A getRelatedTopicsResult() 0 10 3
A getInterestOverTimeResult() 0 10 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