Completed
Push — master ( a52326...01a9e5 )
by Emily
02:33
created

PropertyAccessTrait   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 0
loc 48
ccs 0
cts 34
cp 0
rs 10
c 1
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getReflectionComposite() 0 14 2
A __construct() 0 4 1
A initPropertyAccessTrait() 0 8 1
A __get() 0 4 1
A __set() 0 4 1
1
<?php
2
3
namespace Spaark\Composite\Traits;
4
5
use Spaark\CompositeUtils\Service\ConditionalPropertyAccessor;
6
use Spaark\CompositeUtils\Factory\Reflection\ReflectionCompositeFactory;
7
8
trait PropertyAccessTrait
9
{
10
    protected static $reflectionComposite;
11
12
    protected static function getReflectionComposite()
13
    {
14
        if (!static::$reflectionComposite)
15
        {
16
            static::$reflectComposite =
17
                ReflectionCompositeFactory::fromClassName
18
                (
19
                    get_called_class()
20
                )
21
                ->build();
22
        }
23
24
        return static::$reflectComposite;
25
    }
26
27
    /**
28
     * @var ConditionalPropertyAccessor
29
     */
30
    protected $accessor;
31
32
    public function __construct()
33
    {
34
        $this->initPropertyAccessTrait();
35
    }
36
37
    protected function initPropertyAccessTrait()
38
    {
39
        $this->accessor = new ConditionalPropertyAccessor
40
        (
41
            $this,
42
            self::getReflectionComposite()
43
        );
44
    }
45
46
    public function __get($property)
47
    {
48
        return $this->accessor->getValue($property);
49
    }
50
51
    public function __set($property, $value)
52
    {
53
        $this->accessor->setValue($property, $value);
54
    }
55
}
56