Passed
Push — master ( 5a5557...1f3f4f )
by Francis
01:32
created

Resource::__set()   A

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
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 3
rs 10
1
<?php
2
3
namespace LiveStream\Resources;
4
5
use stdClass;
6
7
class Resource
8
{
9
    /**
10
     * Resource Payload
11
     *
12
     * @var object
13
     */
14
    private $data;
15
16
    /**
17
     * Class Constructor.
18
     *
19
     * @param boolean $init
20
     */
21
    public function __construct(bool $init = true)
22
    {
23
        if ($init) $this->data = new stdClass();
24
    }
25
26
    /**
27
     * Factory Method.
28
     *
29
     * @param  object $object
30
     * @return \LiveStream\Resources\Resource
31
     */
32
    public static function fromObject(object $object): Resource
33
    {
34
        $instance = new static(false);
35
        $instance->data = $object;
36
        return $instance;
37
    }
38
39
    /**
40
     * Magic Setter Method
41
     *
42
     * @param  string $key
43
     * @param  mixed  $value
44
     * @return void
45
     */
46
    public function __set(string $key, $value): void
47
    {
48
        $this->data->$key = $value;
49
    }
50
51
    /**
52
     * Magic Getter Method
53
     *
54
     * @param  string $key
55
     * @return void
56
     */
57
    public function __get(string $key)
58
    {
59
        return $this->data->$key ?? null;
60
    }
61
62
    /**
63
     * Magic Method Isset.
64
     *
65
     * @param  string  $key
66
     * @return boolean
67
     */
68
    public function __isset(string $key)
69
    {
70
        return isset($this->data->$key);
71
    }
72
}
73