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

TVItemChanges::getSeasonChanges()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 7
nc 3
nop 0
dl 0
loc 13
ccs 0
cts 12
cp 0
crap 12
rs 10
c 1
b 0
f 0
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 TVItemChanges extends ItemChanges
28
{
29
    /**
30
     * Constructor
31
     * @param TmdbInterface $tmdb
32
     * @param int $movie_id
33
     * @param array $options
34
     */
35
    public function __construct(TmdbInterface $tmdb, int $movie_id, array $options = array())
36
    {
37
        try {
38
            parent::__construct($tmdb, 'tv', $movie_id, $options);
39
        } catch (TmdbException $ex) {
40
            throw $ex;
41
        }
42
    }
43
44
    /**
45
     * @return \AppendIterator|Results\ItemChange
0 ignored issues
show
Bug introduced by
The type VfacTmdb\Items\Results\ItemChange was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
46
     */
47
    public function getSeasonChanges()
48
    {
49
        $seasonChanges = new \AppendIterator();
50
        foreach ($this->getChangesByKey('season') as $change) {
51
            if (null !== $change->getValueByKey('season_id')) {
52
                $seasonChanges->append(
53
                    (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

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