Passed
Pull Request — master (#48)
by
unknown
12:55
created

TVShowItemChanges   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 19
dl 0
loc 53
ccs 21
cts 21
cp 1
rs 10
c 0
b 0
f 0
wmc 8

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getEpisodeChanges() 0 13 3
A getSeasonChanges() 0 13 3
A __construct() 0 6 2
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
0 ignored issues
show
Bug introduced by
The type VfacTmdb\Items\VfacTmdb\Results\ItemChange was not found. Did you mean VfacTmdb\Results\ItemChange? If so, make sure to prefix the type with \.
Loading history...
47
     */
48 12
    public function getSeasonChanges() : \AppendIterator
49
    {
50 12
        $seasonChanges = new \AppendIterator();
51 12
        foreach ($this->getChangesByKey('season') as $change) {
52 12
            if (null !== $change->getValueByKey('season_id')) {
53 12
                $seasonChanges->append(
54 12
                    (new TVSeasonItemChanges($this->tmdb, $change->getValueByKey('season_id'), $this->params))
0 ignored issues
show
Bug introduced by
It seems like $change->getValueByKey('season_id') can also be of type null; however, parameter $season_id of VfacTmdb\Items\TVSeasonItemChanges::__construct() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

54
                    (new TVSeasonItemChanges($this->tmdb, /** @scrutinizer ignore-type */ $change->getValueByKey('season_id'), $this->params))
Loading history...
55 12
                        ->getChanges()
56
                );
57
            }
58
        }
59
60 12
        return $seasonChanges;
61
    }
62
63
    /**
64
     * Get TV Episode Item Changes for this TV Show
65
     * @return \AppendIterator|VfacTmdb\Results\ItemChange
66
     */
67 6
    public function getEpisodeChanges() : \AppendIterator
68
    {
69 6
        $episodeChanges = new \AppendIterator();
70 6
        foreach ($this->getSeasonChanges() as $seasonChange) {
71 6
            if (null !== $seasonChange->getValueByKey('episode_id')) {
72 6
                $episodeChanges->append(
73 6
                    (new TVEpisodeItemChanges($this->tmdb, $seasonChange->getValueByKey('episode_id'), $this->params))
74 6
                    ->getChanges()
75
                );
76
            }
77
        }
78
79 6
        return $episodeChanges;
80
    }
81
}
82