Passed
Push — master ( 75f027...d75bb0 )
by vincent
01:46
created

Collection   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 102
Duplicated Lines 21.57 %

Coupling/Cohesion

Components 1
Dependencies 7

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 7
dl 22
loc 102
ccs 33
cts 33
cp 1
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getId() 0 4 1
A getName() 0 8 2
A getParts() 0 9 3
A getBackdrops() 11 11 2
A getPosters() 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
12
 */
13
14
15
namespace VfacTmdb\Items;
16
17
use VfacTmdb\Abstracts\Item;
18
use VfacTmdb\Interfaces\Items\CollectionInterface;
19
20
use VfacTmdb\Exceptions\NotFoundException;
21
use VfacTmdb\Traits\ElementTrait;
22
use VfacTmdb\Results;
23
use VfacTmdb\Interfaces\TmdbInterface;
24
25
/**
26
 * Class to manipulate a collection
27
 * @package Tmdb
28
 * @author Vincent Faliès <[email protected]>
29
 * @copyright Copyright (c) 2017
30
 */
31
class Collection extends Item implements CollectionInterface
32
{
33
    use ElementTrait;
34
35
    /**
36
     * Configuration
37
     * @var \stdClass
38
     */
39
    protected $conf = null;
40
    /**
41
     * Id
42
     * @var int
43
     */
44
    protected $id = null;
45
    /**
46
     * Tmdb object
47
     * @var TmdbInterface
48
     */
49
    protected $tmdb = null;
50
51
    /**
52
     * Constructor
53
     * @param TmdbInterface $tmdb
54
     * @param int $collection_id
55
     * @param array $options
56
     */
57 19
    public function __construct(TmdbInterface $tmdb, int $collection_id, array $options = array())
58
    {
59 19
        parent::__construct($tmdb, $collection_id, $options, 'collection');
60
61 18
        $this->setElementTrait($this->data);
62 18
    }
63
64
    /**
65
     * Get collection ID
66
     * @return int
67
     */
68 2
    public function getId() : int
69
    {
70 2
        return $this->id;
71
    }
72
73
    /**
74
     * Get collection name
75
     * @return string
76
     * @throws NotFoundException
77
     */
78 2
    public function getName() : string
79
    {
80 2
        if (isset($this->data->name)) {
81 1
            return $this->data->name;
82
        }
83 1
        $this->logger->error('Collection name not found', array('collection_id' => $this->id));
84 1
        throw new NotFoundException;
85
    }
86
87
    /**
88
     * Get collection parts
89
     * @return \Generator
90
     */
91 2
    public function getParts() : \Generator
92
    {
93 2
        if (!empty($this->data->parts)) {
94 1
            foreach ($this->data->parts as $part) {
95 1
                $movie = new Results\Movie($this->tmdb, $part);
96 1
                yield $movie;
97
            }
98
        }
99 2
    }
100
101
    /**
102
     * Get collection backdrops
103
     * @return \Generator|Results\Image
104
     */
105 9 View Code Duplication
    public function getBackdrops() : \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...
106
    {
107 9
        $params = [];
108 9
        $this->tmdb->checkOptionLanguage($this->params, $params);
109 9
        $data = $this->tmdb->getRequest('collection/' . (int) $this->id . '/images', $params);
110
111 9
        foreach ($data->backdrops as $b) {
112 9
            $image = new Results\Image($this->tmdb, $this->id, $b);
113 9
            yield $image;
114
        }
115 1
    }
116
117
    /**
118
     * Get collection posters
119
     * @return \Generator|Results\Image
120
     */
121 1 View Code Duplication
    public function getPosters() : \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...
122
    {
123 1
        $params = [];
124 1
        $this->tmdb->checkOptionLanguage($this->params, $params);
125 1
        $data = $this->tmdb->getRequest('collection/' . (int) $this->id . '/images', $params);
126
127 1
        foreach ($data->posters as $b) {
128 1
            $image = new Results\Image($this->tmdb, $this->id, $b);
129 1
            yield $image;
130
        }
131 1
    }
132
}
133