Passed
Branch release/1.5.0 (d52397)
by vincent
02:35
created

TVSeason::getPosters()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 10
Ratio 100 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
dl 10
loc 10
ccs 6
cts 6
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 0
crap 2
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
use vfalies\tmdb\Traits\ElementTrait;
9
use vfalies\tmdb\lib\Guzzle\Client as HttpClient;
10
use vfalies\tmdb\Results\TVEpisode;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, vfalies\tmdb\Items\TVEpisode.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
11
use vfalies\tmdb\Results\Image;
12
13
class TVSeason extends Item implements TVSeasonInterface
14
{
15
16
    use ElementTrait;
17
18
    protected $season_number;
19
20
    /**
21
     * Constructor
22
     * @param \vfalies\tmdb\Tmdb $tmdb
23
     * @param int $tv_id
24
     * @param int $season_number
25
     * @param array $options
26
     * @throws Exception
27
     */
28 33
    public function __construct(Tmdb $tmdb, $tv_id, $season_number, array $options = array())
29
    {
30 33
        parent::__construct($tmdb, $season_number, $options, 'tv/'.$tv_id);
31
32 33
        $this->season_number = $season_number;
33 33
    }
34
35 2
    public function getId()
36
    {
37 2
        if ( ! empty($this->data->id))
38
        {
39 1
            return (int) $this->data->id;
40
        }
41 1
        return 0;
42
    }
43
44 2
    public function getAirDate()
45
    {
46 2
        if ( ! empty($this->data->air_date))
47
        {
48 1
            return $this->data->air_date;
49
        }
50 1
        return '';
51
    }
52
53 2
    public function getEpisodeCount()
54
    {
55 2
        if ( ! empty($this->data->episodes))
56
        {
57 1
            return count($this->data->episodes);
58
        }
59 1
        return 0;
60
    }
61
62 2
    public function getSeasonNumber()
63
    {
64 2
        if ( ! empty($this->data->season_number))
65
        {
66 1
            return (int) $this->data->season_number;
67
        }
68 1
        return 0;
69
    }
70
71 20
    public function getEpisodes()
72
    {
73 20
        if ( ! empty($this->data->episodes))
74
        {
75 19
            foreach ($this->data->episodes as $episode)
76
            {
77 19
                $episode = new TVEpisode($this->tmdb, $episode);
78 19
                yield $episode;
79
            }
80
        }
81 2
    }
82
83 2
    public function getName()
84
    {
85 2
        if ( ! empty($this->data->name))
86
        {
87 1
            return $this->data->name;
88
        }
89 1
        return '';
90
    }
91
92 2
    public function getOverview()
93
    {
94 2
        if ( ! empty($this->data->overview))
95
        {
96 1
            return $this->data->overview;
97
        }
98 1
        return '';
99
    }
100
101 1 View Code Duplication
    public function getPosters()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
102
    {
103 1
        $data = $this->tmdb->sendRequest(new HttpClient(new \GuzzleHttp\Client()), '/tv/'.(int) $this->id.'/seasons/'.$this->season_number.'/images', null, $this->params);
104
105 1
        foreach ($data->posters as $b)
106
        {
107 1
            $image = new Image($this->tmdb, $this->id, $b);
108 1
            yield $image;
109
        }
110 1
    }
111
112
}
113