Completed
Push — master ( 4057ea...5a0495 )
by Ben
14:29 queued 14:25
created

PropertyTrait::__get()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 4
rs 10
c 1
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Benrowe\Properties;
6
7
trait PropertyTrait
8
{
9
    private $propertyManager;
10
11
    public function __call($methodName, $params)
12
    {
13
        $pm = $this->getPropertyManager();
14
        if (!method_exists($pm, $methodName)) {
15
            throw new \Exception('Unknown method '.$methodName);
16
        }
17
        return call_user_func_array([$pm, $methodName], $params);
18
    }
19
20
    public function __get($key)
21
    {
22
        return $this->getPropertyManager()->getValue($key);
23
    }
24
25
    public function __set($key, $value)
26
    {
27
        return $this->getPropertyManager()->setValue($key, $value);
28
    }
29
30
    private function getPropertyManager()
31
    {
32
        if (!$this->propertyManager) {
33
            $this->propertyManager = new Manager;
34
        }
35
        return $this->propertyManager;
36
    }
37
}
38