Entity   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
eloc 4
dl 0
loc 39
c 0
b 0
f 0
rs 10
ccs 8
cts 8
cp 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __get() 0 3 1
A toArray() 0 3 1
A __construct() 0 4 1
A __isset() 0 3 1
1
<?php
2
3
// ---------------------------------------------------------------------
4
//
5
//  Copyright (C) 2018-2024 Artem Rodygin
6
//
7
//  You should have received a copy of the MIT License along with
8
//  this file. If not, see <https://opensource.org/licenses/MIT>.
9
//
10
// ---------------------------------------------------------------------
11
12
namespace Linode;
13
14
/**
15
 * An abstract read-only entity.
16
 */
17
abstract class Entity
18
{
19
    /**
20
     * @param LinodeClient $client Linode API client.
21
     * @param array        $data   JSON data retrieved from Linode.
22
     */
23 3
    public function __construct(
24
        protected LinodeClient $client,
25
        protected array $data = []
26 3
    ) {}
27
28
    /**
29
     * Checks whether the specified property exists in the entity.
30
     *
31
     * @param string $name Property name.
32
     */
33 1
    public function __isset(string $name): bool
34
    {
35 1
        return array_key_exists($name, $this->data);
36
    }
37
38
    /**
39
     * Returns current value of the specified property, or `null` if the property doesn't exist.
40
     *
41
     * @param string $name Property name.
42
     *
43
     * @return null|mixed Property value.
44
     */
45 1
    public function __get(string $name): mixed
46
    {
47 1
        return $this->data[$name] ?? null;
48
    }
49
50
    /**
51
     * Converts the entity into an array.
52
     */
53 1
    public function toArray(): array
54
    {
55 1
        return $this->data;
56
    }
57
}
58