Passed
Pull Request — master (#48)
by
unknown
05:45
created

TVShowItemChanges   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 20
c 0
b 0
f 0
dl 0
loc 54
ccs 22
cts 22
cp 1
rs 10
wmc 8

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 2
A getEpisodeChanges() 0 13 3
A getSeasonChanges() 0 14 3
1
<?php declare(strict_types=1);
2
/**
3
 * This file is part of the Tmdb package.
4
 *
5
 * (c) Vincent Faliès <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @author Vincent Faliès <[email protected]>
11
 * @copyright Copyright (c) 2017-2021
12
 */
13
14
15
namespace VfacTmdb\Items;
16
17
use VfacTmdb\Abstracts\Items\ItemChanges;
18
use VfacTmdb\Exceptions\TmdbException;
19
use VfacTmdb\Interfaces\TmdbInterface;
20
21
/**
22
 * TV Item Changes class
23
 * @package Tmdb
24
 * @author Steve Richter <[email protected]>
25
 * @copyright Copyright (c) 2021
26
 */
27
class TVShowItemChanges extends ItemChanges
28
{
29
    /**
30
     * Constructor
31
     * @param TmdbInterface $tmdb
32
     * @param int $movie_id
33
     * @param array $options
34
     */
35 21
    public function __construct(TmdbInterface $tmdb, int $movie_id, array $options = array())
36
    {
37
        try {
38 21
            parent::__construct($tmdb, 'tv', $movie_id, $options);
39 3
        } catch (TmdbException $ex) {
40 3
            throw $ex;
41
        }
42 18
    }
43
44
    /**
45
     * Get TV Season Item Changes for this TV Show
46
     * @return \AppendIterator|\VfacTmdb\Results\ItemChange
47
     */
48 12
    public function getSeasonChanges() : \AppendIterator
49
    {
50 12
        $seasonChanges = new \AppendIterator();
51 12
        foreach ($this->getChangesByKey('season') as $change) {
52 12
            $seasonId = $change->getValueByKey('season_id');
53 12
            if (null !== $seasonId) {
54 12
                $seasonChanges->append(
55 12
                    (new TVSeasonItemChanges($this->tmdb, $seasonId, $this->params))
56 12
                        ->getChanges()
57
                );
58
            }
59
        }
60
61 12
        return $seasonChanges;
62
    }
63
64
    /**
65
     * Get TV Episode Item Changes for this TV Show
66
     * @return \AppendIterator|\VfacTmdb\Results\ItemChange
67
     */
68 6
    public function getEpisodeChanges() : \AppendIterator
69
    {
70 6
        $episodeChanges = new \AppendIterator();
71 6
        foreach ($this->getSeasonChanges() as $seasonChange) {
72 6
            if (null !== $seasonChange->getValueByKey('episode_id')) {
73 6
                $episodeChanges->append(
74 6
                    (new TVEpisodeItemChanges($this->tmdb, $seasonChange->getValueByKey('episode_id'), $this->params))
75 6
                    ->getChanges()
76
                );
77
            }
78
        }
79
80 6
        return $episodeChanges;
81
    }
82
}
83