MappableTrait::setEntityAttribute()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 2
1
<?php
2
3
namespace Analogue\ORM;
4
5
/**
6
 * Share behaviour of Entities/ValueObjects and allow
7
 * implementing mapping for custom classes
8
 */
9
trait MappableTrait
10
{
11
    /**
12
     * The Entity's Attributes
13
     * @var array
14
     */
15
    protected $attributes = [];
16
17
    /**
18
     * Method used by the mapper to set the object
19
     * attribute raw values (hydration)
20
     *
21
     * @param array $attributes
22
     *
23
     * @return void
24
     */
25
    public function setEntityAttributes(array $attributes)
26
    {
27
        $this->attributes = $attributes;
28
    }
29
30
    /**
31
     * Method used by the mapper to get the
32
     * raw object's values.
33
     *
34
     * @return array
35
     */
36
    public function getEntityAttributes()
37
    {
38
        return $this->attributes;
39
    }
40
41
    /**
42
     * Method used by the mapper to set raw
43
     * key-value pair
44
     *
45
     * @param string $key
46
     * @param string $value
47
     *
48
     * @return void
49
     */
50
    public function setEntityAttribute($key, $value)
51
    {
52
        $this->attributes[$key] = $value;
53
    }
54
55
    /**
56
     * Method used by the mapper to get single
57
     * key-value pair
58
     *
59
     * @param  string $key
60
     * @return mixed|null
61
     */
62
    public function getEntityAttribute($key)
63
    {
64
        if (array_key_exists($key, $this->attributes)) {
65
            return $this->attributes[$key];
66
        } else {
67
            return null;
68
        }
69
    }
70
}
71