Completed
Push — master ( 1f9a78...118fca )
by Emily
02:07
created

PropertyAccessTrait   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 94.44%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 0
loc 48
ccs 17
cts 18
cp 0.9444
rs 10
c 0
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
 * This file is part of the Composite Utils package.
4
 *
5
 * (c) Emily Shepherd <[email protected]>
6
 *
7
 * For the full copyright and licence information, please view the
8
 * LICENSE.md file that was distributed with this source code.
9
 *
10
 * @package spaark/composite-utils
11
 * @author Emily Shepherd <emily@emilyshepherd>
12
 * @license MIT
13
 */
14
15
namespace Spaark\CompositeUtils\Traits;
16
17
use Spaark\CompositeUtils\Service\ConditionalPropertyAccessor;
18
use Spaark\CompositeUtils\Factory\Reflection\ReflectionCompositeFactory;
19
20
trait PropertyAccessTrait
21
{
22
    protected static $reflectionComposite;
23
24 4
    protected static function getReflectionComposite()
25
    {
26 4
        if (!static::$reflectionComposite)
27
        {
28
            static::$reflectionComposite =
29 1
                ReflectionCompositeFactory::fromClassName
30
                (
31
                    get_called_class()
32
                )
33 1
                ->build();
34
        }
35
36 4
        return static::$reflectionComposite;
37
    }
38
39
    /**
40
     * @var ConditionalPropertyAccessor
41
     */
42
    protected $accessor;
43
44 4
    public function __construct()
45
    {
46 4
        $this->initPropertyAccessTrait();
47 4
    }
48
49 4
    protected function initPropertyAccessTrait()
50
    {
51 4
        $this->accessor = new ConditionalPropertyAccessor
52
        (
53
            $this,
54 4
            self::getReflectionComposite()
55
        );
56 4
    }
57
58 2
    public function __get($property)
59
    {
60 2
        return $this->accessor->getValue($property);
61
    }
62
63 2
    public function __set($property, $value)
64
    {
65 2
        $this->accessor->setValue($property, $value);
66 1
    }
67
}
68