Completed
Push — master ( af699b...936638 )
by Maxim
04:45
created

AbstractEntity::set()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 2
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace WebComplete\core\entity;
4
5
use WebComplete\core\utils\traits\TraitData;
6
7
abstract class AbstractEntity
8
{
9
    use TraitData {
10
        mapFromArray as traitMapFromArray;
11
        mapToArray as traitMapToArray;
12
    }
13
14
    protected $id;
15
16
    /**
17
     * @return int|string|null
18
     */
19
    public function getId()
20
    {
21
        return $this->id;
22
    }
23
24
    /**
25
     * @param int|string $id
26
     */
27
    public function setId($id)
28
    {
29
        $this->id = $id;
30
    }
31
32
    /**
33
     * @param array $data
34
     * @param bool $update
35
     */
36
    public function mapFromArray(array $data, bool $update = false)
37
    {
38
        $this->traitMapFromArray($data, $update);
39
        if (isset($data['id'])) {
40
            $this->setId($data['id']);
41
        }
42
    }
43
44
    /**
45
     * @return array
46
     */
47
    public function mapToArray(): array
48
    {
49
        $result = $this->traitMapToArray();
50
        $result['id'] = $this->getId();
51
        return $result;
52
    }
53
}
54