PhpObject::__toString()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
eloc 1
nc 1
nop 0
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