Genres   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 82
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 23
dl 0
loc 82
ccs 24
cts 24
cp 1
rs 10
c 0
b 0
f 0
wmc 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A genreItemGenerator() 0 4 2
A getList() 0 15 3
A __construct() 0 3 1
A getMovieList() 0 6 2
A getTVList() 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 18
    public function __construct(TmdbInterface $tmdb)
42
    {
43 18
        $this->tmdb = $tmdb;
44 18
    }
45
46
    /**
47
     * Get movie genres list
48
     * @param array $options
49
     * @return \Generator
50
     * @throws TmdbException
51
     */
52 12
    public function getMovieList(array $options = array()) : \Generator
53
    {
54
        try {
55 12
            return $this->getList('genre/movie/list', $options);
56 6
        } catch (TmdbException $ex) {
57 6
            throw $ex;
58
        }
59
    }
60
61
    /**
62
     * Get TV genres list
63
     * @param array $options
64
     * @return \Generator
65
     * @throws TmdbException
66
     */
67 6
    public function getTVList(array $options = array()) : \Generator
68
    {
69
        try {
70 6
            return $this->getList('genre/tv/list', $options);
71 3
        } catch (TmdbException $ex) {
72 3
            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 18
    private function getList(string $type, array $options) : \Generator
84
    {
85
        try {
86 18
            $params = [];
87 18
            $this->tmdb->checkOptionLanguage($options, $params);
88 18
            $response = $this->tmdb->getRequest($type, $params);
89
90 9
            $genres = [];
91 9
            if (isset($response->genres)) {
92 6
                $genres = $response->genres;
93
            }
94
95 9
            return $this->genreItemGenerator($genres);
96 9
        } catch (TmdbException $ex) {
97 9
            throw $ex;
98
        }
99
    }
100
101
    /**
102
     * Genre Item generator method
103
     * @param array $results
104
     * @return \Generator
105
     */
106 9
    private function genreItemGenerator(array $results) : \Generator
107
    {
108 9
        foreach ($results as $result) {
109 6
            yield $result;
110
        }
111 3
    }
112
}
113