PhpObject::fromArray()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
1
<?php
2
3
namespace Ghc\Rosetta\Messages;
4
5
class PhpObject extends Message
6
{
7
    /**
8
     * @return \stdClass
9
     */
10
    public function newData()
11
    {
12
        return new \stdClass();
13
    }
14
15
    /**
16
     * Get the instance as an array.
17
     *
18
     * @return array
19
     */
20
    public function toArray()
21
    {
22
        return get_object_vars($this->getData());
23
    }
24
25
    /**
26
     * @param array $data
27
     *
28
     * @return self
29
     */
30
    public function fromArray($data)
31
    {
32
        $o = $this->getData();
33
34
        foreach ($data as $key => $value) {
35
            $o->$key = $value;
36
        }
37
38
        return $this->setData($o);
39
    }
40
41
    /**
42
     * @return string
43
     */
44
    public function __toString()
45
    {
46
        return serialize($this->toArray());
47
    }
48
}
49