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

Item::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\Items;
4
5
use vfalies\tmdb\Tmdb;
6
use vfalies\tmdb\lib\CurlRequest;
7
8
abstract class Item
9
{
10
    protected $data = null;
11
    protected $conf = null;
12
    protected $id   = null;
13
    protected $tmdb = null;
14
15
    /**
16
     * Constructor
17
     * @param \vfalies\tmdb\Tmdb $tmdb
18
     * @param int $item_id
19
     * @param array $options
20
     * @param string $item_name
21
     * @throws \Exception
22
     */
23 71
    public function __construct(Tmdb $tmdb, int $item_id, array $options, string $item_name)
24
    {
25
        try
26
        {
27 71
            $this->id   = (int) $item_id;
28 71
            $this->tmdb = $tmdb;
29 71
            $this->conf = $this->tmdb->getConfiguration();
30 71
            $params     = $this->tmdb->checkOptions($options);
31 71
            $this->data = $this->tmdb->sendRequest(new CurlRequest(), $item_name . '/'.(int) $item_id, null, $params);
32
        }
33 3
        catch (\Exception $ex)
34
        {
35 3
            throw new \Exception($ex->getMessage(), $ex->getCode(), $ex);
36
        }
37 68
    }
38
39
    /**
40
     * Get item poster
41
     * @param string $size
42
     * @return string
43
     */
44 12 View Code Duplication
    public function getPoster(string $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...
45
    {
46 12
        if (isset($this->data->poster_path))
47
        {
48 9
            if (!isset($this->conf->images->base_url))
49
            {
50 3
                throw new \Exception('base_url configuration not found');
51
            }
52 6
            if (!in_array($size, $this->conf->images->poster_sizes))
53
            {
54 3
                throw new \Exception('Incorrect poster size : ' . $size);
55
            }
56 3
            return $this->conf->images->base_url . $size . $this->data->poster_path;
57
        }
58 3
        return '';
59
    }
60
61
    /**
62
     * Get item backdrop
63
     * @param string $size
64
     * @return string|null
65
     */
66 12 View Code Duplication
    public function getBackdrop(string $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...
67
    {
68 12
        if (isset($this->data->backdrop_path))
69
        {
70 9
            if (!isset($this->conf->images->base_url))
71
            {
72 3
                throw new \Exception('base_url configuration not found');
73
            }
74 6
            if (!in_array($size, $this->conf->images->backdrop_sizes))
75
            {
76 3
                throw new \Exception('Incorrect backdrop size : ' . $size);
77
            }
78 3
            return $this->conf->images->base_url . $size . $this->data->backdrop_path;
79
        }
80 3
        return '';
81
    }
82
83
}
84