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

Results   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 5
Bugs 1 Features 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 33
ccs 9
cts 9
cp 1
rs 10
c 5
b 1
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 18 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