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

src/Abstracts/Results.php (1 issue)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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
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