Passed
Branch account (392693)
by vincent
02:25
created

TVItem   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
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 41
ccs 19
cts 19
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 11 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
     * Get posters params configuration from child object
33
     * @return \stdClass
34
     */
35 2
    protected function getPostersParams() : \stdClass
36
    {
37 2
        $url = 'tv/' . $this->tv_id . '/season/' . $this->season_number;
0 ignored issues
show
Bug introduced by
The property tv_id does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
Bug introduced by
The property season_number does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
38 2
        $key = 'posters';
39 2
        if (isset($this->episode_number)) {
40 1
            $url .= '/episode/' . $this->episode_number;
0 ignored issues
show
Bug introduced by
The property episode_number does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
41 1
            $key = 'stills';
42
        }
43 2
        $url .= '/images';
44
45 2
        $params = new \stdClass;
46 2
        $params->url = $url;
47 2
        $params->key = $key;
48
49 2
        return $params;
50
    }
51
52
    /**
53
     * Image posters
54
     * @return \Generator|Results\Image
55
     */
56 2
    public function getPosters() : \Generator
57
    {
58 2
        $params = $this->getPostersParams();
59 2
        $key    = $params->key;
60 2
        $data   = $this->tmdb->getRequest($params->url, $this->params);
61
62 2
        foreach ($data->$key as $b) {
63 2
            $image = new Results\Image($this->tmdb, $this->id, $b);
64 2
            yield $image;
65
        }
66 2
    }
67
}
68