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

PropertyAccessTrait::initPropertyAccessTrait()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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