Completed
Branch master (6321d1)
by Gawain
10:09 queued 03:32
created

Entity::setId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 4
rs 10
c 1
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
namespace Bolt\Storage\Entity;
3
4
use ArrayAccess;
5
use JsonSerializable;
6
7
/**
8
 * An abstract class that other entities can inherit. Provides automatic getters and setters along
9
 * with serialization.
10
 */
11
abstract class Entity implements ArrayAccess, JsonSerializable
12
{
13
    use MagicAttributeTrait;
14
    use EntitySerializeTrait;
15
    use EntityArrayAccessTrait;
16
17
    /** @var int */
18
    protected $id;
19
20
    /**
21
     * Constructor.
22
     *
23
     * @param array $data
24
     */
25
    public function __construct($data = [])
26
    {
27
        foreach ($data as $key => $value) {
28
            $method = 'set' . ucfirst($key);
29
            $this->$method($value);
30
        }
31
    }
32
33
    /**
34
     * @return int
35
     */
36
    public function getId()
37
    {
38
        return $this->id;
39
    }
40
41
    /**
42
     * @param int $id
43
     */
44
    public function setId($id)
45
    {
46
        $this->id = $id;
47
    }
48
49
    public function __toString()
50
    {
51
        return (string) $this->getId();
52
    }
53
}
54