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

PropertyTrait::getPropertyManager()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 7
rs 9.4285
c 1
b 0
f 0
cc 2
eloc 4
nc 2
nop 0
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