Passed
Branch account (ed4c74)
by vincent
02:20
created

PeopleItemCredit   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 62
Duplicated Lines 32.26 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 3
dl 20
loc 62
ccs 22
cts 22
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 2
A getCrew() 10 10 3
A getCast() 10 10 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 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\Abstracts\Items;
16
17
use VfacTmdb\Abstracts\Item;
18
use VfacTmdb\Exceptions\TmdbException;
19
use VfacTmdb\Interfaces\TmdbInterface;
20
21
/**
22
 * abstract item class
23
 * @package Tmdb
24
 * @author Vincent Faliès <[email protected]>
25
 * @copyright Copyright (c) 2017
26
 */
27
abstract class PeopleItemCredit extends Item
28
{
29
    /**
30
     * People item crew class name
31
     * @var string
32
     */
33
    public $crew_class;
34
    /**
35
     * People item cast class name
36
     * @var string
37
     */
38
    public $cast_class;
39
40
    /**
41
     * Constructor
42
     * @param TmdbInterface $tmdb
43
     * @param string $item_type (possible value : movie / tv)
44
     * @param int $item_id
45
     * @param array $options
46
     */
47 40
    public function __construct(TmdbInterface $tmdb, string $item_type, int $item_id, array $options = array())
48
    {
49
        try {
50 40
            $this->tmdb   = $tmdb;
51 40
            $this->logger = $tmdb->getLogger();
52 40
            $this->params = $this->tmdb->checkOptions($options);
53 40
            $this->data   = $this->tmdb->getRequest('person/' . $item_id . '/' . $item_type . '_credits', $this->params);
54 2
        } catch (TmdbException $ex) {
55 2
            throw $ex;
56
        }
57 38
    }
58
59
    /**
60
     * Crew
61
     * @return \Generator
62
     */
63 20 View Code Duplication
    public function getCrew() : \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...
64
    {
65 20
        if (!empty($this->data->crew)) {
66 20
            foreach ($this->data->crew as $c) {
67 20
                $crew_class = $this->crew_class;
68 20
                $crew = new $crew_class($this->tmdb, $c);
69 20
                yield $crew;
70
            }
71
        }
72 2
    }
73
74
    /**
75
     * Cast
76
     * @return \Generator
77
     */
78 18 View Code Duplication
    public function getCast() : \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...
79
    {
80 18
        if (!empty($this->data->cast)) {
81 18
            foreach ($this->data->cast as $c) {
82 18
                $cast_class = $this->cast_class;
83 18
                $cast = new $cast_class($this->tmdb, $c);
84 18
                yield $cast;
85
            }
86
        }
87 2
    }
88
}
89