Passed
Push — master ( aa4df2...69fe56 )
by Orkhan
01:34
created

Resource::__get()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 7
c 0
b 0
f 0
rs 10
cc 2
nc 2
nop 1
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
    private $properties = [];
11
12
    /**
13
     * Resource constructor.
14
     *
15
     * @param array $properties
16
     */
17
    public function __construct(array $properties = [])
18
    {
19
        $this->properties = $properties;
20
    }
21
22
    /**
23
     * @param string $name
24
     *
25
     * @throws ResourcePropertyNotFoundException
26
     *
27
     * @return mixed
28
     */
29
    public function __get(string $name)
30
    {
31
        if (!isset($this->properties[$name])) {
32
            throw new ResourcePropertyNotFoundException($name);
33
        }
34
35
        return $this->properties[$name];
36
    }
37
38
    public function jsonSerialize()
39
    {
40
        return $this->properties;
41
    }
42
}
43