Passed
Pull Request — master (#41)
by
unknown
03:59
created

TVNetwork   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 106
Duplicated Lines 20.75 %

Coupling/Cohesion

Components 2
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 14
lcom 2
cbo 5
dl 22
loc 106
ccs 38
cts 38
cp 1
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getId() 0 4 1
A getName() 0 7 2
A getHeadquarters() 0 7 2
A getHomepage() 0 7 2
A getOriginCountry() 0 7 2
A getAlternativeNames() 11 11 2
A getLogos() 11 11 2

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 declare(strict_types = 1);
2
/**
3
 * This file is part of the Tmdb package.
4
 *
5
 * (c) Vincent Faliès <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @author Vincent Faliès <[email protected]>
11
 * @copyright Copyright (c) 2017-2020
12
 */
13
14
15
namespace VfacTmdb\Items;
16
17
use VfacTmdb\Abstracts\Item;
18
use VfacTmdb\Interfaces\Items\TVNetworkInterface;
19
use VfacTmdb\Traits\ElementTrait;
20
use VfacTmdb\Interfaces\TmdbInterface;
21
use VfacTmdb\Results;
22
23
/**
24
 * TVNetwork class
25
 * @package Tmdb
26
 * @author Steve Richter <[email protected]>
27
 * @copyright Copyright (c) 2017-2020
28
 */
29
class TVNetwork extends Item implements TVNetworkInterface
30
{
31
    use ElementTrait;
32
33
    /**
34
     * Constructor
35
     * @param TmdbInterface $tmdb
36
     * @param int $network_id
37
     * @param array $options
38
     */
39 84
    public function __construct(TmdbInterface $tmdb, int $network_id, array $options = array())
40
    {
41 84
        parent::__construct($tmdb, $network_id, $options, 'network');
42
43 81
        $this->setElementTrait($this->data);
44 81
    }
45
46
    /**
47
     * Get TV Network id
48
     * @return int
49
     */
50 9
    public function getId() : int
51
    {
52 9
        return $this->id;
53
    }
54
55
    /**
56
     * Get TV Network name
57
     * @return string
58
     */
59 6
    public function getName() : string
60
    {
61 6
        if (isset($this->data->name)) {
62 3
            return $this->data->name;
63
        }
64 3
        return '';
65
    }
66
67
    /**
68
     * Get TV Network headquarters
69
     * @return string
70
     */
71 6
    public function getHeadquarters() : string
72
    {
73 6
        if (isset($this->data->headquarters)) {
74 3
            return $this->data->headquarters;
75
        }
76 3
        return '';
77
    }
78
79
    /**
80
     * Get TV Network homepage
81
     * @return string
82
     */
83 6
    public function getHomepage() : string
84
    {
85 6
        if (isset($this->data->homepage)) {
86 3
            return $this->data->homepage;
87
        }
88 3
        return '';
89
    }
90
91
    /**
92
     * Get TV Network origin country
93
     * @return string
94
     */
95 6
    public function getOriginCountry() : string
96
    {
97 6
        if (isset($this->data->origin_country)) {
98 3
            return $this->data->origin_country;
99
        }
100 3
        return '';
101
    }
102
103
    /**
104
     * Alternative names list
105
     * @return \Generator|Results\Name
106
     */
107 12 View Code Duplication
    public function getAlternativeNames() : \Generator
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...
108
    {
109 12
        $params = [];
110 12
        $this->tmdb->checkOptionLanguage($this->params, $params);
111 12
        $data = $this->tmdb->getRequest('network/' . (int) $this->id . '/alternative_names', $params);
112
113 12
        foreach ($data->results as $n) {
114 12
            $name = new Results\AlternativeName($this->tmdb, $this->id, $n);
115 12
            yield $name;
116
        }
117 3
    }
118
119
    /**
120
     * Logos list
121
     * @return \Generator|Results\Logo
122
     */
123 36 View Code Duplication
    public function getLogos() : \Generator
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...
124
    {
125 36
        $params = [];
126 36
        $this->tmdb->checkOptionLanguage($this->params, $params);
127 36
        $data = $this->tmdb->getRequest('network/' . (int) $this->id . '/images', $params);
128
129 36
        foreach ($data->logos as $logo) {
130 36
            $image = new Results\Logo($this->tmdb, $this->id, $logo);
131 36
            yield $image;
132
        }
133 3
    }
134
}
135