Completed
Push — master ( 3294e4...4057ea )
by Ben
42:41 queued 29:25
created

PropertyTrait   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 31
ccs 12
cts 12
cp 1
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 3
    public function __call($methodName, $params)
12
    {
13 3
        $pm = $this->getPropertyManager();
14 3
        if (!method_exists($pm, $methodName)) {
15
            throw new \Exception('Unknown method '.$methodName);
16
        }
17 3
        return call_user_func_array([$pm, $methodName], $params);
18
    }
19
20 6
    public function __get($key)
21
    {
22 6
        return $this->getPropertyManager()->getValue($key);
23
    }
24
25 3
    public function __set($key, $value)
26
    {
27 3
        return $this->getPropertyManager()->setValue($key, $value);
28
    }
29
30 6
    private function getPropertyManager()
31
    {
32 6
        if (!$this->propertyManager) {
33 6
            $this->propertyManager = new Manager;
34
        }
35 6
        return $this->propertyManager;
36
    }
37
}
38