Model   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 81
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 0
dl 0
loc 81
ccs 0
cts 34
cp 0
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getPrimaryKey() 0 4 1
A setAttributes() 0 12 3
getAttributeMap() 0 1 ?
A toArray() 0 4 1
A __get() 0 8 2
A __set() 0 4 1
A __isset() 0 4 1
1
<?php
2
3
namespace DJStarCOM\BookingComSDK\Models;
4
5
/**
6
 * Class Model
7
 * @package DJStarCOM\BookingComSDK\Models
8
 */
9
abstract class Model
10
{
11
    /**
12
     * @var array
13
     */
14
    protected static $attributeMap = [];
15
16
    /**
17
     * Model primary key. Adding to collection with this key.
18
     * @return string|int|null
19
     */
20
    public function getPrimaryKey()
21
    {
22
        return null;
23
    }
24
25
    /**
26
     * @param array $data
27
     */
28
    public function setAttributes(array $data): void
29
    {
30
        $prepareData = array_intersect_key($data, $this->getAttributeMap());
31
32
        foreach ($prepareData as $key => $value) {
33
            if (!property_exists($this, $key)) {
34
                continue;
35
            }
36
            $key        = str_replace('-', '_', $key);
37
            $this->$key = $value;
38
        }
39
    }
40
41
    /**
42
     * @return array
43
     */
44
    abstract protected function getAttributeMap(): array;
45
46
    /**
47
     * Converts the model into an array.
48
     * @return array
49
     */
50
    public function toArray(): array
51
    {
52
        return get_object_vars($this);
53
    }
54
55
    /**
56
     * PHP getter magic method.
57
     *
58
     * @param string $name property name
59
     * @return mixed property value
60
     */
61
    public function __get($name)
62
    {
63
        if (!property_exists($this, $name)) {
64
            return null;
65
        }
66
67
        return $this->$name;
68
    }
69
70
    /**
71
     * PHP setter magic method.
72
     *
73
     * @param string $name property name
74
     * @param mixed $value property value
75
     */
76
    public function __set($name, $value): void
77
    {
78
        $this->$name = $value;
79
    }
80
81
    /**
82
     * @param string $name
83
     * @return bool
84
     */
85
    public function __isset($name)
86
    {
87
        return property_exists($this, $name);
88
    }
89
}
90