ChangeProtectedAttribute   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 1
lcom 0
cbo 0
dl 0
loc 17
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A modifyAttribute() 0 7 1
1
<?php
2
declare(strict_types = 1);
3
4
namespace Common;
5
6
use ReflectionProperty;
7
8
/**
9
 * Reusable component to allow changing private/protected attributes
10
 *
11
 * @author Luís Otávio Cobucci Oblonczyk <[email protected]>
12
 */
13
trait ChangeProtectedAttribute
14
{
15
    /**
16
     * Configures the attribute with the given value
17
     *
18
     * @param object $object
19
     * @param string $name
20
     * @param mixed $value
21
     */
22
    public function modifyAttribute($object, $name, $value)
23
    {
24
        $attribute = new ReflectionProperty($object, $name);
25
26
        $attribute->setAccessible(true);
27
        $attribute->setValue($object, $value);
28
    }
29
}
30