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

Genres   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 92
Duplicated Lines 23.91 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 2
dl 22
loc 92
ccs 24
cts 24
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getMovieList() 11 11 2
A getTVList() 11 11 2
A getList() 0 20 3
A genreItemGenerator() 0 7 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
2
3
namespace vfalies\tmdb;
4
5
class Genres implements Interfaces\GenresInterface
6
{
7
8
    protected $tmdb = null;
9
10
    /**
11
     * Constructor
12
     * @param \vfalies\tmdb\Tmdb $tmdb
13
     * @throws Exception
14
     */
15 5
    public function __construct(Tmdb $tmdb)
16
    {
17 5
        $this->tmdb = $tmdb;
18 5
    }
19
20
    /**
21
     * Get movie genres list
22
     * @param array $options
23
     * @return \Generator
24
     * @throws \Exception
25
     */
26 3 View Code Duplication
    public function getMovieList(array $options = array()): \Generator
1 ignored issue
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...
27
    {
28
        try
29
        {            
30 3
            return $this->getList('genre/movie/list', $options);
31
        }
32 1
        catch (\Exception $ex)
33
        {
34 1
            throw new \Exception($ex->getMessage(), $ex->getCode(), $ex);
35
        }
36
    }
37
38
    /**
39
     * Get TV genres list
40
     * @param array $options
41
     * @return \Generator
42
     * @throws \Exception
43
     */
44 2 View Code Duplication
    public function getTVList(array $options = array()): \Generator
1 ignored issue
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...
45
    {
46
        try
47
        {
48 2
            return $this->getList('genre/tv/list', $options);
49
        }
50 1
        catch (\Exception $ex)
51
        {
52 1
            throw new \Exception($ex->getMessage(), $ex->getCode(), $ex);
53
        }
54
    }
55
56
    /**
57
     * Generic getter list
58
     * @param string $type
59
     * @param array $options
60
     * @return \Generator
61
     * @throws \Exception
62
     */
63 5
    private function getList(string $type, array $options): \Generator
64
    {
65
        try
66
        {
67 5
            $params   = $this->tmdb->checkOptions($options);
68 5
            $response = $this->tmdb->sendRequest(new CurlRequest(), $type, null, $params);
69
70 3
            $genres = [];
71 3
            if (isset($response->genres))
72
            {
73 2
                $genres = $response->genres;
74
            }
75
76 3
            return $this->genreItemGenerator($genres);
77
        }
78 2
        catch (\Exception $ex)
79
        {
80 2
            throw new \Exception($ex->getMessage(), $ex->getCode(), $ex);
81
        }
82
    }
83
84
    /**
85
     * Genre Item generator method
86
     * @param array $results
87
     */
88 3
    private function genreItemGenerator(array $results): \Generator
89
    {
90 3
        foreach ($results as $result)
91
        {
92 2
            yield $result;
93
        }
94 1
    }
95
96
}
97