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

Genres::genreItemGenerator()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 3
nc 2
nop 1
crap 2
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