Passed
Pull Request — master (#9)
by vincent
02:52
created

Results::__construct()   B

Complexity

Conditions 5
Paths 3

Size

Total Lines 16
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 5

Importance

Changes 0
Metric Value
dl 0
loc 16
ccs 8
cts 8
cp 1
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 7
nc 3
nop 2
crap 5
1
<?php
2
3
namespace vfalies\tmdb\Abstracts;
4
5
use vfalies\tmdb\Tmdb;
6
7
abstract class Results extends Element implements \vfalies\tmdb\Interfaces\ResultsInterface
8
{
9
10
    protected $id            = null;
11
    protected $poster_path   = null;
12
    protected $backdrop_path = null;
13
14
    /**
15
     * Constructor
16
     * @param \vfalies\tmdb\Tmdb $tmdb
17
     * @param \stdClass $result
18
     * @throws \Exception
19
     */
20 37
    public function __construct(Tmdb $tmdb, \stdClass $result)
21
    {
22
        // Valid input object
23 37
        $properties = get_object_vars($this);
24 37
        foreach (array_keys($properties) as $property)
25
        {
26 37
            if ($property != 'conf' && $property != 'data' && !property_exists($result, $property))
27
            {
28 37
                throw new \Exception('Incorrect input for ' . __CLASS__ . ' object. Property "' . $property . '" not found');
29
            }
30
        }
31
32
        // Configuration
33 37
        $this->conf = $tmdb->getConfiguration();
34 37
        $this->data = $result;
35 37
    }
36
37
}
38