Passed
Push — master ( 67aa47...d37a32 )
by vincent
02:27
created

Collection::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 3
crap 1
1
<?php
2
3
namespace vfalies\tmdb\Items;
4
5
use vfalies\tmdb\Interfaces\CollectionInterface;
6
use vfalies\tmdb\Tmdb;
7
8
class Collection extends Item implements CollectionInterface
9
{
10
11
    // Private loaded data
12
    protected $data = null;
13
    protected $conf = null;
14
    protected $id   = null;
15
    protected $tmdb = null;
16
17
    /**
18
     * Constructor
19
     * @param Tmdb $tmdb
20
     * @param int $collection_id
21
     * @param array $options
22
     */
23 15
    public function __construct(Tmdb $tmdb, int $collection_id, array $options = array())
24
    {
25 15
        parent::__construct($tmdb, $collection_id, $options, 'collection');
26 14
    }
27
28
    /**
29
     * Get collection ID
30
     * @return int
31
     * @throws \Exception
32
     */
33 2
    public function getId(): int
34
    {
35 2
        return $this->id;
36
    }
37
38
    /**
39
     * Get collection name
40
     * @return string
41
     * @throws \Exception
42
     */
43 2
    public function getName(): string
44
    {
45 2
        if (isset($this->data->name))
46
        {
47 1
            return $this->data->name;
48
        }
49 1
        throw new \Exception('Collection name can not be found');
50
    }
51
52
    /**
53
     * Get collection parts
54
     * @return Generator
55
     */
56 2
    public function getParts(): \Generator
57
    {
58 2
        if (!empty($this->data->parts))
59
        {
60 1
            foreach ($this->data->parts as $part)
61
            {
62 1
                $movie = new \vfalies\tmdb\Results\Movie($this->tmdb, $part);
63 1
                yield $movie;
64
            }
65
        }
66 1
    }
67
68
}
69