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

Results::__construct()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 16
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 4

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 16
ccs 8
cts 8
cp 1
rs 9.2
cc 4
eloc 7
nc 3
nop 2
crap 4
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
    protected $property_blacklist = ['property_blacklist', 'conf', 'data'];
14
15
    /**
16
     * Constructor
17
     * @param \vfalies\tmdb\Tmdb $tmdb
18
     * @param \stdClass $result
19
     * @throws \Exception
20
     */
21 37
    public function __construct(Tmdb $tmdb, \stdClass $result)
22
    {
23
        // Valid input object
24 37
        $properties = get_object_vars($this);
25 37
        foreach (array_keys($properties) as $property)
26
        {
27 37
            if ( ! in_array($property, $this->property_blacklist) && !property_exists($result, $property))
28
            {
29 37
                throw new \Exception('Incorrect input for ' . __CLASS__ . ' object. Property "' . $property . '" not found');
30
            }
31
        }
32
33
        // Configuration
34 37
        $this->conf = $tmdb->getConfiguration();
35 37
        $this->data = $result;
36 37
    }
37
38
}
39