Passed
Push — master ( 9f17d2...e5ff49 )
by
unknown
03:30
created

TVSeason::getEpisodes()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 6
cts 6
cp 1
rs 9.6666
c 0
b 0
f 0
cc 3
eloc 5
nc 3
nop 0
crap 3
1
<?php
2
3
namespace vfalies\tmdb\Items;
4
5
use vfalies\tmdb\Abstracts\Item;
6
use vfalies\tmdb\Interfaces\Items\TVSeasonInterface;
7
use vfalies\tmdb\Tmdb;
8
9
class TVSeason extends Item implements TVSeasonInterface
10
{
11
12
    /**
13
     * Constructor
14
     * @param \vfalies\tmdb\Tmdb $tmdb
15
     * @param int $tv_id
16
     * @param int $season_number
17
     * @param array $options
18
     * @throws Exception
19
     */
20 24
    public function __construct(Tmdb $tmdb, int $tv_id, int $season_number, array $options = array())
21
    {
22 24
        parent::__construct($tmdb, $season_number, $options, 'tv/'.$tv_id);
23 24
    }
24
25 2
    public function getId(): int
26
    {
27 2
        if (! empty($this->data->id)) {
28 1
            return (int) $this->data->id;
29
        }
30 1
        return 0;
31
    }
32
33 2
    public function getAirDate(): string
34
    {
35 2
        if (! empty($this->data->air_date)) {
36 1
            return $this->data->air_date;
37
        }
38 1
        return '';
39
    }
40
41 2
    public function getEpisodeCount(): int
42
    {
43 2
        if (! empty($this->data->episodes)) {
44 1
            return count($this->data->episodes);
45
        }
46 1
        return 0;
47
    }
48
49 2
    public function getSeasonNumber(): int
50
    {
51 2
        if (! empty($this->data->season_number)) {
52 1
            return (int) $this->data->season_number;
53
        }
54 1
        return 0;
55
    }
56
57 12
    public function getEpisodes(): \Generator
58
    {
59 12
        if (! empty($this->data->episodes)) {
60 11
            foreach ($this->data->episodes as $episode) {
61 11
                $episode = new \vfalies\tmdb\Results\TVEpisode($this->tmdb, $episode);
62 11
                yield $episode;
63
            }
64
        }
65 1
    }
66
67 2
    public function getName(): string
68
    {
69 2
        if (! empty($this->data->name)) {
70 1
            return $this->data->name;
71
        }
72 1
        return '';
73
    }
74
75 2
    public function getOverview(): string
76
    {
77 2
        if (! empty($this->data->overview)) {
78 1
            return $this->data->overview;
79
        }
80 1
        return '';
81
    }
82
}
83