Jobs::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
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 VfacTmdb\Catalogs;
16
17
use VfacTmdb\Interfaces\TmdbInterface;
18
19
use VfacTmdb\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 TmdbInterface $tmdb
39
     */
40 6
    public function __construct(TmdbInterface $tmdb)
41
    {
42 6
        $this->tmdb = $tmdb;
43 6
    }
44
45
    /**
46
     * Get job list
47
     * @return \Generator|\stdClass
48
     * @throws TmdbException
49
     */
50 6
    public function getList() : \Generator
51
    {
52
        try {
53 6
            $response = $this->tmdb->getRequest('job/list');
54
55 3
            $results = [];
56 3
            if (isset($response->jobs)) {
57 3
                foreach ($response->jobs as $j) {
58 3
                    $result             = new \stdClass();
59 3
                    $result->department = $j->department;
60 3
                    $result->jobs       = $j->job_list;
61
62 3
                    $results[] = $result;
63
                }
64
            }
65 3
        } catch (TmdbException $ex) {
66 3
            throw $ex;
67
        }
68 3
        return $this->genreItemGenerator($results);
69
    }
70
71
    /**
72
     * Genre Item generator method
73
     * @param array $results
74
     * @return \Generator
75
     */
76 3
    private function genreItemGenerator(array $results) : \Generator
77
    {
78 3
        foreach ($results as $result) {
79 3
            yield $result;
80
        }
81 3
    }
82
}
83