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

Results::getPoster()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 6

Duplication

Lines 12
Ratio 100 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 0
Metric Value
dl 12
loc 12
ccs 6
cts 6
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 6
nc 3
nop 1
crap 3
1
<?php
2
3
namespace vfalies\tmdb\Results;
4
5
abstract class Results implements \vfalies\tmdb\Interfaces\ResultsInterface
6
{
7
8
    protected $id            = null;
9
    protected $poster_path   = null;
10
    protected $backdrop_path = null;
11
    protected $conf          = null;
12
13
    /**
14
     * Constructor
15
     * @param \vfalies\tmdb\Tmdb $tmdb
16
     * @param \stdClass $result
17
     * @throws \Exception
18
     */
19 37
    public function __construct(\vfalies\tmdb\Tmdb $tmdb, \stdClass $result)
20
    {
21
        // Valid input object
22 37
        $properties = get_object_vars($this);
23 37
        foreach (array_keys($properties) as $property)
24
        {
25 37
            if ($property != 'conf' && !property_exists($result, $property))
26
            {
27 37
                throw new \Exception('Incorrect input for ' . __CLASS__ . ' object. Property "' . $property . '" not found');
28
            }
29
        }
30
31
        // Configuration
32 37
        $this->conf = $tmdb->getConfiguration();
33 37
    }
34
35
    /**
36
     * Get poster
37
     * @return string
38
     */
39 9 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...
40
    {
41 9
        if (!isset($this->conf->images->base_url))
42
        {
43 3
            throw new \Exception('base_url configuration not found');
44
        }
45 6
        if (!in_array($size, $this->conf->images->poster_sizes))
46
        {
47 3
            throw new \Exception('Incorrect poster size : ' . $size);
48
        }
49 3
        return $this->conf->images->base_url . $size . $this->poster_path;
50
    }
51
52
    /**
53
     * Get backdrop
54
     * @return string
55
     */
56 9 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...
57
    {
58 9
        if (!isset($this->conf->images->base_url))
59
        {
60 3
            throw new \Exception('base_url configuration not found');
61
        }
62 6
        if (!in_array($size, $this->conf->images->backdrop_sizes))
63
        {
64 3
            throw new \Exception('Incorrect backdrop size : ' . $size);
65
        }
66 3
        return $this->conf->images->base_url . $size . $this->backdrop_path;
67
    }
68
69
}
70