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

InterestOverTimeResult::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 3
crap 1
1
<?php declare(strict_types=1);
2
3
namespace GSoares\GoogleTrends\Result;
4
5
use DateTimeInterface;
6
use JsonSerializable;
7
8
/**
9
 * @author Gabriel Felipe Soares <[email protected]>
10
 */
11
class InterestOverTimeResult implements JsonSerializable
12
{
13
    /**
14
     * @var DateTimeInterface
15
     */
16
    private $interestAt;
17
18
    /**
19
     * @var int[]
20
     */
21
    private $values;
22
23
    /**
24
     * @var bool
25
     */
26
    private $hasData;
27
28 3
    public function __construct(DateTimeInterface $at, array $values, bool $hasData)
29
    {
30 3
        $this->interestAt = $at;
31 3
        $this->values = $values;
32 3
        $this->hasData = $hasData;
33 3
    }
34
35 1
    public function getInterestAt(): DateTimeInterface
36
    {
37 1
        return $this->interestAt;
38
    }
39
40 1
    public function getValues(): array
41
    {
42 1
        return $this->values;
43
    }
44
45 1
    public function getFirstValue(): int
46
    {
47 1
        return $this->values[0] ?? 0;
48
    }
49
50 1
    public function hasData(): bool
51
    {
52 1
        return $this->hasData;
53
    }
54
55
    /**
56
     * @inheritDoc
57
     */
58 1
    public function jsonSerialize(): array
59
    {
60
        return [
61 1
            'interestAt' => $this->getInterestAt()->format(DATE_ATOM),
62 1
            'values' => $this->getValues(),
63 1
            'firstValue' => $this->getFirstValue(),
64 1
            'hasData' => $this->hasData()
65
        ];
66
    }
67
}
68