Passed
Pull Request — master (#7)
by vincent
02:21
created

Collection   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 2
dl 0
loc 60
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0

4 Methods

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