PeopleItemCredit::getCast()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 5
nc 3
nop 0
dl 0
loc 7
ccs 6
cts 6
cp 1
crap 3
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
12
 */
13
14
15
namespace VfacTmdb\Abstracts\Items;
16
17
use VfacTmdb\Abstracts\Item;
18
use VfacTmdb\Exceptions\TmdbException;
19
use VfacTmdb\Interfaces\TmdbInterface;
20
21
/**
22
 * abstract item class
23
 * @package Tmdb
24
 * @author Vincent Faliès <[email protected]>
25
 * @copyright Copyright (c) 2017
26
 */
27
abstract class PeopleItemCredit extends Item
28
{
29
    /**
30
     * People item crew class name
31
     * @var string
32
     */
33
    public $crew_class;
34
    /**
35
     * People item cast class name
36
     * @var string
37
     */
38
    public $cast_class;
39
40
    /**
41
     * Constructor
42
     * @param TmdbInterface $tmdb
43
     * @param string $item_type (possible value : movie / tv)
44
     * @param int $item_id
45
     * @param array $options
46
     */
47 120
    public function __construct(TmdbInterface $tmdb, string $item_type, int $item_id, array $options = array())
48
    {
49
        try {
50 120
            $this->tmdb   = $tmdb;
51 120
            $this->logger = $tmdb->getLogger();
52
53 120
            $this->tmdb->checkOptionLanguage($options, $this->params);
54
55 120
            $this->data = $this->tmdb->getRequest('person/' . $item_id . '/' . $item_type . '_credits', $this->params);
56 6
        } catch (TmdbException $ex) {
57 6
            throw $ex;
58
        }
59 114
    }
60
61
    /**
62
     * Crew
63
     * @return \Generator
64
     */
65 60
    public function getCrew() : \Generator
66
    {
67 60
        if (!empty($this->data->crew)) {
68 60
            foreach ($this->data->crew as $c) {
69 60
                $crew_class = $this->crew_class;
70 60
                $crew = new $crew_class($this->tmdb, $c);
71 60
                yield $crew;
72
            }
73
        }
74 6
    }
75
76
    /**
77
     * Cast
78
     * @return \Generator
79
     */
80 54
    public function getCast() : \Generator
81
    {
82 54
        if (!empty($this->data->cast)) {
83 54
            foreach ($this->data->cast as $c) {
84 54
                $cast_class = $this->cast_class;
85 54
                $cast = new $cast_class($this->tmdb, $c);
86 54
                yield $cast;
87
            }
88
        }
89 6
    }
90
}
91