EntityWrapper   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 5
Bugs 1 Features 0
Metric Value
wmc 7
c 5
b 1
f 0
lcom 1
cbo 1
dl 0
loc 78
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setEntityAttributes() 0 4 1
A getEntityAttributes() 0 4 1
A setEntityAttribute() 0 8 1
A getEntityAttribute() 0 9 2
A hasAttribute() 0 10 2
1
<?php
2
3
namespace Analogue\ORM\System\Wrappers;
4
5
/**
6
 * Simple Wrapper for Mappable objects
7
 */
8
class EntityWrapper extends Wrapper
9
{
10
    /**
11
     * Method used by the mapper to set the object
12
     * attribute raw values (hydration)
13
     *
14
     * @param array $attributes
15
     *
16
     * @return void
17
     */
18
    public function setEntityAttributes(array $attributes)
19
    {
20
        $this->entity->setEntityAttributes($attributes);
21
    }
22
23
    /**
24
     * Method used by the mapper to get the
25
     * raw object's values.
26
     *
27
     * @return array
28
     */
29
    public function getEntityAttributes()
30
    {
31
        return $this->entity->getEntityAttributes();
32
    }
33
34
    /**
35
     * Method used by the mapper to set raw
36
     * key-value pair
37
     *
38
     * @param string $key
39
     * @param string $value
40
     *
41
     * @return void
42
     */
43
    public function setEntityAttribute($key, $value)
44
    {
45
        $attributes = $this->entity->getEntityAttributes();
46
47
        $attributes[$key] = $value;
48
49
        $this->entity->setEntityAttributes($attributes);
50
    }
51
52
    /**
53
     * Method used by the mapper to get single
54
     * key-value pair
55
     *
56
     * @param  string $key
57
     * @return mixed|null
58
     */
59
    public function getEntityAttribute($key)
60
    {
61
        if ($this->hasAttribute($key)) {
62
            $attributes = $this->entity->getEntityAttributes();
63
            return $attributes[$key];
64
        } else {
65
            return null;
66
        }
67
    }
68
69
    /**
70
     * Test if a given attribute exists
71
     *
72
     * @param  string $key
73
     * @return boolean
74
     */
75
    public function hasAttribute($key)
76
    {
77
        $attributes = $this->entity->getEntityAttributes();
78
79
        if (array_key_exists($key, $attributes)) {
80
            return true;
81
        } else {
82
            return false;
83
        }
84
    }
85
}
86