Passed
Push — master ( 75f027...d75bb0 )
by vincent
01:46
created

TVItem   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 4
dl 0
loc 61
ccs 21
cts 21
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getPostersParams() 0 16 2
A getPosters() 0 15 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
12
 */
13
14
15
namespace VfacTmdb\Abstracts\Items;
16
17
use VfacTmdb\Results;
18
use VfacTmdb\Abstracts\Item;
19
use VfacTmdb\Traits\ElementTrait;
20
21
/**
22
 * abstract TV item class
23
 * @package Tmdb
24
 * @author Vincent Faliès <[email protected]>
25
 * @copyright Copyright (c) 2017
26
 */
27
abstract class TVItem extends Item
28
{
29
    use ElementTrait;
30
31
    /**
32
     * Season number
33
     * @var int
34
     */
35
    protected $season_number;
36
    /**
37
     * Episode number
38
     * @var int
39
     */
40
    protected $episode_number;
41
    /**
42
     * TVShow Id
43
     * @var  int
44
     */
45
    protected $tv_id;
46
47
    /**
48
     * Get posters params configuration from child object
49
     * @return \stdClass
50
     */
51 2
    protected function getPostersParams() : \stdClass
52
    {
53 2
        $url = 'tv/' . $this->tv_id . '/season/' . $this->season_number;
54 2
        $key = 'posters';
55 2
        if (isset($this->episode_number)) {
56 1
            $url .= '/episode/' . $this->episode_number;
57 1
            $key = 'stills';
58
        }
59 2
        $url .= '/images';
60
61 2
        $params = new \stdClass;
62 2
        $params->url = $url;
63 2
        $params->key = $key;
64
65 2
        return $params;
66
    }
67
68
    /**
69
     * Image posters
70
     * @return \Generator|Results\Image
71
     */
72 2
    public function getPosters() : \Generator
73
    {
74 2
        $params = $this->getPostersParams();
75 2
        $key    = $params->key;
76
77 2
        $options = [];
78 2
        $this->tmdb->checkOptionLanguage($this->params, $options);
79
80 2
        $data   = $this->tmdb->getRequest($params->url, $options);
81
82 2
        foreach ($data->$key as $b) {
83 2
            $image = new Results\Image($this->tmdb, $this->id, $b);
84 2
            yield $image;
85
        }
86 2
    }
87
}
88