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

Resource   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 64
rs 10
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __set() 0 3 1
A fromObject() 0 5 1
A __isset() 0 3 1
A __construct() 0 3 2
A __get() 0 3 1
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