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

PropertyTrait   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 31
rs 10
c 1
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __call() 0 8 2
A __get() 0 4 1
A __set() 0 4 1
A getPropertyManager() 0 7 2
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