GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 64a210...2d6991 )
by Stan
02:42
created

AbstractEntity::initBuiltInEntities()   C

Complexity

Conditions 8
Paths 14

Size

Total Lines 24
Code Lines 13

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 24
rs 5.7377
cc 8
eloc 13
nc 14
nop 1
1
<?php
2
3
/**
4
 * Base abstract class for supported by Telegram entity classes.
5
 *
6
 * @package Teebot (Telegram bot framework)
7
 *
8
 * @author Stanislav Drozdov <[email protected]>
9
 */
10
11
namespace Teebot\Entity;
12
13
use Teebot\Traits\Property;
14
15
abstract class AbstractEntity
16
{
17
    use Property;
18
19
    const ENTITY_TYPE = 'AbstractEntity';
20
21
    protected $parent;
22
23
    protected $builtInEntities = [];
24
25
    protected $supportedProperties = [];
26
27
    /**
28
     * Returns parent entity
29
     *
30
     * @return AbstractEntity
31
     */
32
    public function getParent()
33
    {
34
        return $this->parent;
35
    }
36
37
    /**
38
     * Sets parent entity
39
     *
40
     * @param AbstractEntity $parent Parent entity
41
     */
42
    public function setParent(AbstractEntity $parent)
43
    {
44
        $this->parent = $parent;
45
    }
46
47
    /**
48
     * Constructs extended entity's class and sets properties from array if passed.
49
     *
50
     * @param array $data Array with properties to set
51
     */
52
    public function __construct(array $data = [])
53
    {
54
        if (empty($data)) {
55
            return;
56
        }
57
        
58
        $this->setProperties($data);
59
        $this->initBuiltInEntities($data);
60
    }
61
62
    /**
63
     * Returns entity type
64
     *
65
     * @return string
66
     */
67
    public function getEntityType() : string
68
    {
69
        return static::ENTITY_TYPE;
70
    }
71
72
    /**
73
     * Initialises built-in entity classes if any.
74
     *
75
     * @param array $data Array with data to pass to newly created instance of built-in entity
76
     */
77
    protected function initBuiltInEntities(array $data)
78
    {
79
        if (empty($this->builtInEntities)) {
80
            return;
81
        }
82
83
        foreach ($this->builtInEntities as $name => $class) {
84
85
            $initValues = null;
86
87
            if (property_exists($this, $name)) {
88
                if (isset($this->{$name})) {
89
                    $initValues = $this->{$name};
90
                } elseif (isset($data[$name])) {
91
                    $initValues = $data[$name];
92
                }
93
            }
94
95
            if ($initValues) {
96
                $object = class_exists($class) ? new $class($initValues) : null;
97
                $this->setProperty($name, $object);
98
            }
99
        }
100
    }
101
}
102