Completed
Pull Request — master (#2)
by
unknown
08:22
created

Collection::getBackdrop()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 16
Code Lines 8

Duplication

Lines 16
Ratio 100 %

Code Coverage

Tests 8
CRAP Score 4

Importance

Changes 0
Metric Value
dl 16
loc 16
ccs 8
cts 8
cp 1
rs 9.2
c 0
b 0
f 0
cc 4
eloc 8
nc 4
nop 1
crap 4
1
<?php
2
3
namespace vfalies\tmdb;
4
5
class Collection implements Interfaces\CollectionInterface
6
{
7
8
    // Private loaded data
9
    private $data = null;
10
    private $conf = null;
11
    private $id   = null;
12
    private $tmdb = null;
13
14
    /**
15
     * Constructor
16
     * @param \vfalies\tmdb\Tmdb $tmdb
17
     * @throws \Exception
18
     */
19 15 View Code Duplication
    public function __construct(\vfalies\tmdb\Tmdb $tmdb, $collection_id, array $options = array())
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
20
    {
21
        try
22
        {
23 15
            $this->id   = (int) $collection_id;
24 15
            $this->tmdb = $tmdb;
25 15
            $this->conf = $this->tmdb->getConfiguration();
26
27 15
            $params     = $this->tmdb->checkOptions($options);
28 15
            $this->data = $this->tmdb->sendRequest(new CurlRequest(), 'collection/' . (int) $collection_id, null, $params);
29
        }
30 1
        catch (\Exception $ex)
31
        {
32 1
            throw new \Exception($ex->getMessage(), $ex->getCode(), $ex);
33
        }
34 14
    }
35
36
    /**
37
     * Get collection ID
38
     * @return int
39
     * @throws \Exception
40
     */
41 2
    public function getId(): int
42
    {
43 2
        return $this->id;
44
    }
45
46
    /**
47
     * Get collection name
48
     * @return string
49
     * @throws \Exception
50
     */
51 2
    public function getName(): string
52
    {
53 2
        if (isset($this->data->name))
54
        {
55 1
            return $this->data->name;
56
        }
57 1
        throw new \Exception('Collection name can not be found');
58
    }
59
60
    /**
61
     * Get collection poster
62
     * @param string $size
63
     * @return string
64
     * @throws \Exception
65
     */
66 4 View Code Duplication
    public function getPoster($size = 'w185'): string
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
67
    {
68 4
        if (isset($this->data->poster_path))
69
        {
70 3
            if (!isset($this->conf->images->base_url))
71
            {
72 1
                throw new \Exception('base_url configuration not found');
73
            }
74 2
            if (!in_array($size, $this->conf->images->poster_sizes))
75
            {
76 1
                throw new \Exception('Incorrect poster size : ' . $size);
77
            }
78 1
            return $this->conf->images->base_url . $size . $this->data->poster_path;
79
        }
80 1
        throw new \Exception('Collection poster path can not be found');
81
    }
82
83
    /**
84
     * Get collection backdrop
85
     * @param string $size
86
     * @return string
87
     * @throws \Exception
88
     */
89 4 View Code Duplication
    public function getBackdrop($size = 'w780'): string
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
90
    {
91 4
        if (isset($this->data->backdrop_path))
92
        {
93 3
            if (!isset($this->conf->images->base_url))
94
            {
95 1
                throw new \Exception('base_url configuration not found');
96
            }
97 2
            if (!in_array($size, $this->conf->images->backdrop_sizes))
98
            {
99 1
                throw new \Exception('Incorrect backdrop size : ' . $size);
100
            }
101 1
            return $this->conf->images->base_url . $size . $this->data->backdrop_path;
102
        }
103 1
        throw new \Exception('Collection backdrop path can not be found');
104
    }
105
106
    /**
107
     * Get collection parts
108
     * @return Generator|SearchMovieResult
109
     */
110 2
    public function getParts(): \Generator
111
    {
112 2
        if (!empty($this->data->parts))
113
        {
114 1
            foreach ($this->data->parts as $part)
115
            {
116 1
                $movie = new Results\Movie($this->tmdb, $part);
117 1
                yield $movie;
118
            }
119
        }
120 1
    }
121
122
}
123