PropertyAccessorTrait::setObjectProperty()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

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