AllReadableTrait   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getPropertyAccessor() 0 9 2
A __get() 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 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 <[email protected]>
12
 * @license MIT
13
 */
14
15
namespace Spaark\CompositeUtils\Traits;
16
17
use Spaark\CompositeUtils\Service\RawPropertyAccessor;
18
19
/**
20
 * Classes with this trait will allow all of their properties to be read
21
 * externally, but will not allow writing
22
 */
23
trait AllReadableTrait
24
{
25
    /**
26
     * @var RawPropertyAccessor
27
     */
28
    protected $accessor;
29
30
    /**
31
     * Returns the RawPropertyAccessor for this object, or constructs
32
     * one on the fly if one does not yet exist
33
     *
34
     * @return RawPropertyAccessor
35
     */
36 63
    protected function getPropertyAccessor()
37
    {
38 63
        if (!$this->accessor)
39
        {
40 53
            $this->accessor = new RawPropertyAccessor($this);
41
        }
42
43 63
        return $this->accessor;
44
    }
45
46
    /**
47
     * Gets the value of a property using the RawPropertyAccessor
48
     *
49
     * @param string $property The property to get
50
     * @return mixed The property value
51
     */
52 63
    public function __get($property)
53
    {
54 63
        return $this->getPropertyAccessor()->getRawValue($property);
55
    }
56
}
57