Completed
Pull Request — master (#29)
by vincent
02:44
created

Jobs::getList()   B

Complexity

Conditions 4
Paths 7

Size

Total Lines 26
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 26
ccs 13
cts 13
cp 1
rs 8.5806
c 0
b 0
f 0
cc 4
eloc 14
nc 7
nop 1
crap 4
1
<?php
2
3
/**
4
 * This file is part of the Tmdb package.
5
 *
6
 * (c) Vincent Faliès <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 *
11
 * @author Vincent Faliès <[email protected]>
12
 * @copyright Copyright (c) 2017
13
 */
14
15
namespace vfalies\tmdb\Catalogs;
16
17
use vfalies\tmdb\Interfaces\TmdbInterface;
18
use vfalies\tmdb\lib\Guzzle\Client as HttpClient;
19
use vfalies\tmdb\Exceptions\TmdbException;
20
21
/**
22
 * Class to get jobs list with department
23
 * @package Tmdb
24
 * @author Vincent Faliès <[email protected]>
25
 * @copyright Copyright (c) 2017
26
 */
27
class Jobs
28
{
29
30
    /**
31
     * Tmdb object
32
     * @var TmdbInterface
33
     */
34
    protected $tmdb = null;
35
36
    /**
37
     * Constructor
38
     * @param \vfalies\tmdb\Interfaces\TmdbInterface; $tmdb
0 ignored issues
show
Documentation introduced by
The doc-type \vfalies\tmdb\Interfaces\TmdbInterface; could not be parsed: Expected "|" or "end of type", but got ";" at position 38. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
39
     */
40 2
    public function __construct(TmdbInterface $tmdb)
41
    {
42 2
        $this->tmdb = $tmdb;
43 2
    }
44
45
    /**
46
     * Get job list
47
     * @param array $options
48
     * @return \Generator|\stdClass
49
     * @throws \vfalies\tmdb\Catalogs\TmdbException
50
     */
51 2
    public function getList(array $options = array())
52
    {
53
        try
54
        {
55 2
            $params   = $this->tmdb->checkOptions($options);
56 2
            $response = $this->tmdb->sendRequest(new HttpClient(new \GuzzleHttp\Client()), 'job/list', null, $params);
57
58 1
            $results = [];
59 1
            if (isset($response->jobs))
60
            {
61 1
                foreach ($response->jobs as $j)
62
                {
63 1
                    $result             = new \stdClass();
64 1
                    $result->department = $j->department;
65 1
                    $result->jobs       = $j->job_list;
66
67 1
                    $results[] = $result;
68
                }
69
            }
70
        }
71 1
        catch (TmdbException $ex)
72
        {
73 1
            throw $ex;
74
        }
75 1
        return $this->genreItemGenerator($results);
76
    }
77
78
    /**
79
     * Genre Item generator method
80
     * @param array $results
81
     */
82 1
    private function genreItemGenerator(array $results)
83
    {
84 1
        foreach ($results as $result)
85
        {
86 1
            yield $result;
87
        }
88 1
    }
89
}
90