Resource::jsonSerialize()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Orkhanahmadov\Sipgate\Resources;
4
5
use JsonSerializable;
6
use Orkhanahmadov\Sipgate\Exceptions\ResourcePropertyNotFoundException;
7
8
abstract class Resource implements JsonSerializable
9
{
10
    /**
11
     * @var array
12
     */
13
    private $properties = [];
14
15
    /**
16
     * Resource constructor.
17
     *
18
     * @param array $properties
19
     */
20
    public function __construct(array $properties = [])
21
    {
22
        $this->properties = $properties;
23
    }
24
25
    /**
26
     * @param string $name
27
     *
28
     * @return mixed
29
     * @throws ResourcePropertyNotFoundException
30
     */
31
    public function __get(string $name)
32
    {
33
        if (! isset($this->properties[$name])) {
34
            throw new ResourcePropertyNotFoundException($name);
35
        }
36
37
        return $this->properties[$name];
38
    }
39
40
    /**
41
     * @return array
42
     */
43
    public function jsonSerialize()
44
    {
45
        return $this->properties;
46
    }
47
}
48