Passed
Branch release/1.5.0 (5f009d)
by vincent
05:05
created

Jobs::getList()   B

Complexity

Conditions 4
Paths 6

Size

Total Lines 25
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 4.1967

Importance

Changes 0
Metric Value
dl 0
loc 25
ccs 10
cts 13
cp 0.7692
rs 8.5806
c 0
b 0
f 0
cc 4
eloc 13
nc 6
nop 1
crap 4.1967
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
20
/**
21
 * Class to get jobs list with department
22
 * @package Tmdb
23
 * @author Vincent Faliès <[email protected]>
24
 * @copyright Copyright (c) 2017
25
 */
26
class Jobs
27
{
28
29
    /**
30
     * Tmdb object
31
     * @var \vfalies\tmdb\Tmdb
32
     */
33
    protected $tmdb = null;
34
35
    /**
36
     * Constructor
37
     * @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...
38
     */
39 1
    public function __construct(TmdbInterface $tmdb)
40
    {
41 1
        $this->tmdb = $tmdb;
0 ignored issues
show
Documentation Bug introduced by
$tmdb is of type object<vfalies\tmdb\Interfaces\TmdbInterface>, but the property $tmdb was declared to be of type object<vfalies\tmdb\Tmdb>. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
42 1
    }
43
44
    /**
45
     * Get job list
46
     * @param array $options
47
     * @return \Generator|\stdClass
48
     * @throws \vfalies\tmdb\Catalogs\TmdbException
49
     */
50 1
    public function getList(array $options = array())
51
    {
52
        try
53
        {
54 1
            $params   = $this->tmdb->checkOptions($options);
55 1
            $response = $this->tmdb->sendRequest(new HttpClient(new \GuzzleHttp\Client()), 'job/list', null, $params);
56
57 1
            $jobs = [];
0 ignored issues
show
Unused Code introduced by
$jobs is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
58 1
            if (isset($response->jobs))
59
            {
60 1
                foreach ($response->jobs as $j)
61
                {
62 1
                    $result             = new \stdClass();
63 1
                    $result->department = $j->department;
64 1
                    $result->jobs       = $j->job_list;
65
66 1
                    yield $result;
67
                }
68
            }
69
        }
70
        catch (TmdbException $ex)
0 ignored issues
show
Bug introduced by
The class vfalies\tmdb\Catalogs\TmdbException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
71
        {
72
            throw $ex;
73
        }
74
    }
75
76
}
77