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

Genres   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 85
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 2
dl 0
loc 85
ccs 25
cts 25
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getMovieList() 0 8 2
A getTVList() 0 8 2
A getList() 0 17 3
A genreItemGenerator() 0 6 2
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\Catalogs;
16
17
use VfacTmdb\Interfaces\GenresInterface;
18
19
use VfacTmdb\Exceptions\TmdbException;
20
use VfacTmdb\Interfaces\TmdbInterface;
21
22
/**
23
 * Class to get movie and tv show genres
24
 * @package Tmdb
25
 * @author Vincent Faliès <[email protected]>
26
 * @copyright Copyright (c) 2017
27
 */
28
class Genres implements GenresInterface
29
{
30
31
    /**
32
     * Tmdb object
33
     * @var TmdbInterface
34
     */
35
    protected $tmdb = null;
36
37
    /**
38
     * Constructor
39
     * @param TmdbInterface $tmdb
40
     */
41 6
    public function __construct(TmdbInterface $tmdb)
42
    {
43 6
        $this->tmdb = $tmdb;
44 6
    }
45
46
    /**
47
     * Get movie genres list
48
     * @param array $options
49
     * @return \Generator
50
     * @throws TmdbException
51
     */
52 4
    public function getMovieList(array $options = array()) : \Generator
53
    {
54
        try {
55 4
            return $this->getList('genre/movie/list', $options);
56 2
        } catch (TmdbException $ex) {
57 2
            throw $ex;
58
        }
59
    }
60
61
    /**
62
     * Get TV genres list
63
     * @param array $options
64
     * @return \Generator
65
     * @throws TmdbException
66
     */
67 2
    public function getTVList(array $options = array()) : \Generator
68
    {
69
        try {
70 2
            return $this->getList('genre/tv/list', $options);
71 1
        } catch (TmdbException $ex) {
72 1
            throw $ex;
73
        }
74
    }
75
76
    /**
77
     * Generic getter list
78
     * @param string $type
79
     * @param array $options
80
     * @return \Generator
81
     * @throws TmdbException
82
     */
83 6
    private function getList(string $type, array $options) : \Generator
84
    {
85
        try {
86 6
            $params = [];
87 6
            $this->tmdb->checkOptionLanguage($options, $params);
88 6
            $response = $this->tmdb->getRequest($type, $params);
89
90 3
            $genres = [];
91 3
            if (isset($response->genres)) {
92 2
                $genres = $response->genres;
93
            }
94
95 3
            return $this->genreItemGenerator($genres);
96 3
        } catch (TmdbException $ex) {
97 3
            throw $ex;
98
        }
99
    }
100
101
    /**
102
     * Genre Item generator method
103
     * @param array $results
104
     * @return \Generator
105
     */
106 3
    private function genreItemGenerator(array $results) : \Generator
107
    {
108 3
        foreach ($results as $result) {
109 2
            yield $result;
110
        }
111 1
    }
112
}
113