Resource   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
eloc 7
c 1
b 0
f 1
dl 0
loc 38
rs 10

3 Methods

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