StdNormalizable::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php
2
3
namespace Majora\Framework\Normalizer\Model;
4
5
use Majora\Framework\Normalizer\Model\NormalizableInterface;
6
7
/**
8
 * Simple implementation of Normalizable with a StdClass
9
 */
10
class StdNormalizable extends \StdClass implements NormalizableInterface
11
{
12
    /**
13
     * @see NormalizableInterface::getScopes()
14
     */
15
    public static function getScopes()
16
    {
17
        return array();
18
    }
19
20
    /**
21
     * Construct.
22
     *
23
     * @param array $data
24
     */
25
    public function __construct(array $data = array())
26
    {
27
        $this->denormalize($data);
28
    }
29
30
    /**
31
     * @see NormalizableInterface::normalize()
32
     */
33
    public function normalize($scope = 'default')
34
    {
35
        return (array) $this;
36
    }
37
38
    /**
39
     * @see NormalizableInterface::denormalize()
40
     */
41
    public function denormalize(array $data)
42
    {
43
        foreach ($data as $key => $value) {
44
            $this->$key = $value;
45
        }
46
47
        return $this;
48
    }
49
}
50