Passed
Branch account (796afc)
by vincent
02:20
created

TVEpisodeTrait::setTVEpisodeTrait()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 2
crap 1
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\Traits;
16
17
use VfacTmdb\Results;
18
use VfacTmdb\Interfaces\TmdbInterface;
19
20
/**
21
 * TV Episode trait
22
 * @package Tmdb
23
 * @author Vincent Faliès <[email protected]>
24
 * @copyright Copyright (c) 2017
25
 */
26
trait TVEpisodeTrait
27
{
28
    /**
29
     * TVEpisodeTrait object variable
30
     * @var \stdClass
31
     */
32
    protected $tvepisode_trait;
33
34
    /**
35
     * Set TVEpisodeTrait variable
36
     * @param TmdbInterface $tmdb
37
     * @param \stdClass|null $data
38
     * @return void
39
     */
40 45
    protected function setTVEpisodeTrait(TmdbInterface $tmdb, ?\stdClass $data) : void
41
    {
42 45
        $this->tvepisode_trait       = new \stdClass();
43 45
        $this->tvepisode_trait->tmdb = $tmdb;
44 45
        $this->tvepisode_trait->data = $data;
45 45
    }
46
47
    /**
48
     * Get crew of TV Episode
49
     * @return \Generator|Results\Crew
50
     */
51 9
    public function getCrew() : \Generator
52
    {
53 9
        if (!empty($this->tvepisode_trait->data->crew)) {
54 9
            foreach ($this->tvepisode_trait->data->crew as $crew) {
55 9
                $crew->gender = null;
56
57 9
                $return = new Results\Crew($this->tvepisode_trait->tmdb, $crew);
58 9
                yield $return;
59
            }
60
        }
61 2
    }
62
}
63