PropertyAccessorTrait   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 85.71%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 31
ccs 6
cts 7
cp 0.8571
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setObjectProperty() 0 7 2
A __construct() 0 3 1
1
<?php
2
3
namespace DMT\Aura\Psr\Helpers;
4
5
use InvalidArgumentException;
6
7
/**
8
 * Trait PropertyAccessorTrait
9
 *
10
 * @package DMT\Aura\Psr\Helpers
11
 */
12
trait PropertyAccessorTrait
13
{
14
    /** @var object $object */
15
    private $object;
16
17
    /**
18
     * PropertyAccessorTrait constructor.
19
     *
20
     * @param object $object the object ot gain access to.
21
     */
22 96
    public function __construct($object)
23
    {
24 96
        $this->object = $object;
25 96
    }
26
27
    /**
28
     * Access a property.
29
     *
30
     * @param string $property the property to access.
31
     * @param mixed|null $value the value to set.
32
     *
33
     * @return void
34
     * @throws InvalidArgumentException when property does not exists
35
     */
36 90
    public function setObjectProperty($property, $value = null)
37
    {
38 90
        if (!property_exists($this->object, $property)) {
39
            throw new InvalidArgumentException('property does not exists');
40
        }
41
42 90
        $this->object->{$property} = $value;
43
    }
44
}