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 ( 5ac723...c719eb )
by Stan
07:02
created

AbstractEntity   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 87
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 13
lcom 1
cbo 1
dl 0
loc 87
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 2
A getEntityType() 0 4 1
A setParent() 0 4 1
A getParent() 0 4 1
C initBuiltInEntities() 0 24 8
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\Api\Entity;
12
13
use Teebot\Api\Traits\Property;
14
15
abstract class AbstractEntity implements EntityInterface
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
     * Constructs extended entity's class and sets properties from array if passed.
29
     *
30
     * @param array $data Array with properties to set
31
     */
32
    public function __construct(array $data = [])
33
    {
34
        if (empty($data)) {
35
            return;
36
        }
37
        
38
        $this->setProperties($data);
39
        $this->initBuiltInEntities($data);
40
    }
41
42
    /**
43
     * Returns entity type
44
     *
45
     * @return string
46
     */
47
    public function getEntityType()
48
    {
49
        return static::ENTITY_TYPE;
50
    }
51
52
    /**
53
     * Sets parent entity
54
     *
55
     * @param EntityInterface $parent Parent entity
56
     */
57
    public function setParent(EntityInterface $parent = null)
58
    {
59
        $this->parent = $parent;
60
    }
61
62
    /**
63
     * Returns parent entity
64
     *
65
     * @return AbstractEntity
66
     */
67
    public function getParent()
68
    {
69
        return $this->parent;
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