Passed
Push — master ( ddfb88...ea9ad4 )
by vincent
41s
created

Results::__construct()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 18
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 4

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 18
ccs 9
cts 9
cp 1
rs 9.2
cc 4
eloc 8
nc 3
nop 2
crap 4
1
<?php
2
3
namespace vfalies\tmdb\Abstracts;
4
5
use vfalies\tmdb\Tmdb;
6
use vfalies\tmdb\Exceptions\NotFoundException;
7
use vfalies\tmdb\Interfaces\Results\ResultsInterface;
8
9
abstract class Results implements ResultsInterface
10
{
11
12
    protected $property_blacklist = ['property_blacklist', 'conf', 'data', 'logger'];
13
    protected $logger             = null;
14
    protected $conf               = null;
15
16
    /**
17
     * Constructor
18
     * @param \vfalies\tmdb\Tmdb $tmdb
19
     * @param \stdClass $result
20
     * @throws NotFoundException
21
     */
22 44
    public function __construct(Tmdb $tmdb, \stdClass $result)
23
    {
24 44
        $this->logger = $tmdb->logger;
25
26
        // Valid input object
27 44
        $properties = get_object_vars($this);
28 44
        foreach (array_keys($properties) as $property)
29
        {
30 44
            if ( ! in_array($property, $this->property_blacklist) && ! property_exists($result, $property))
31
            {
32 2
                throw new NotFoundException($property);
33
            }
34
        }
35
36
        // Configuration
37 42
        $this->conf = $tmdb->getConfiguration();
38 42
        $this->data = $result;
0 ignored issues
show
Bug introduced by
The property data does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
39 42
    }
40
41
}
42