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

Results   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 65
Duplicated Lines 36.92 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 1
dl 24
loc 65
ccs 19
cts 19
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 15 4
A getPoster() 12 12 3
A getBackdrop() 12 12 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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