Resource::__get()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 3
c 1
b 0
f 1
dl 0
loc 7
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
    /**
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