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

Item   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 71
Duplicated Lines 45.07 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 2
dl 32
loc 71
ccs 25
cts 25
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 15 2
A getPoster() 16 16 4
A getBackdrop() 16 16 4

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\Items;
4
5
abstract class Item
6
{
7
    /**
8
     * Constructor
9
     * @param \vfalies\tmdb\Tmdb $tmdb
10
     * @param int $item_id
11
     * @param array $options
12
     * @param string $item_name
13
     * @throws \Exception
14
     */
15 71
    public function __construct(\vfalies\tmdb\Tmdb $tmdb, int $item_id, array $options, string $item_name)
16
    {
17
        try
18
        {
19 71
            $this->id   = (int) $item_id;
0 ignored issues
show
Bug introduced by
The property id does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
20 71
            $this->tmdb = $tmdb;
0 ignored issues
show
Bug introduced by
The property tmdb does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
21 71
            $this->conf = $this->tmdb->getConfiguration();
0 ignored issues
show
Bug introduced by
The property conf does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
22 71
            $params     = $this->tmdb->checkOptions($options);
23 71
            $this->data = $this->tmdb->sendRequest(new \vfalies\tmdb\CurlRequest(), $item_name . '/'.(int) $item_id, null, $params);
0 ignored issues
show
Bug introduced by
The property data does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
24
        }
25 3
        catch (\Exception $ex)
26
        {
27 3
            throw new \Exception($ex->getMessage(), $ex->getCode(), $ex);
28
        }
29 68
    }
30
31
    /**
32
     * Get item poster
33
     * @param string $size
34
     * @return string
35
     */
36 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...
37
    {
38 12
        if (isset($this->data->poster_path))
39
        {
40 9
            if (!isset($this->conf->images->base_url))
41
            {
42 3
                throw new \Exception('base_url configuration not found');
43
            }
44 6
            if (!in_array($size, $this->conf->images->poster_sizes))
45
            {
46 3
                throw new \Exception('Incorrect poster size : ' . $size);
47
            }
48 3
            return $this->conf->images->base_url . $size . $this->data->poster_path;
49
        }
50 3
        return '';
51
    }
52
53
    /**
54
     * Get item backdrop
55
     * @param string $size
56
     * @return string|null
57
     */
58 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...
59
    {
60 12
        if (isset($this->data->backdrop_path))
61
        {
62 9
            if (!isset($this->conf->images->base_url))
63
            {
64 3
                throw new \Exception('base_url configuration not found');
65
            }
66 6
            if (!in_array($size, $this->conf->images->backdrop_sizes))
67
            {
68 3
                throw new \Exception('Incorrect backdrop size : ' . $size);
69
            }
70 3
            return $this->conf->images->base_url . $size . $this->data->backdrop_path;
71
        }
72 3
        return '';
73
    }
74
75
}
76