Completed
Push — master ( c09ce2...1f44ff )
by Emily
02:06
created

PropertyAccessTrait::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 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 license 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
19
trait PropertyAccessTrait
20
{
21
    use HasReflectorTrait;
22
23
    /**
24
     * @var ConditionalPropertyAccessor
25
     */
26
    protected $accessor;
27
28 4
    protected function getPropertyAccessor()
29
    {
30 4
        if (!$this->accessor)
31
        {
32 4
            $this->accessor = new ConditionalPropertyAccessor
33
            (
34
                $this,
35 4
                self::getReflectionComposite()
36
            );
37
        }
38
39 4
        return $this->accessor;
40
    }
41
42 2
    public function __get($property)
43
    {
44 2
        return $this->getPropertyAccessor()->getValue($property);
45
    }
46
47 2
    public function __set($property, $value)
48
    {
49 2
        $this->getPropertyAccessor()->setValue($property, $value);
50 1
    }
51
}
52