PropertyAccessorTrait::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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