ReflectionHelper   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 30
ccs 15
cts 15
cp 1
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getPropertyValue() 0 8 1
A setPropertyValue() 0 8 1
A invokeMethod() 0 8 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace RazonYang\UnitHelper;
6
7
use ReflectionClass;
8
9
final class ReflectionHelper
10
{
11 3
    public static function invokeMethod(mixed $obj, string $name, mixed ...$args): mixed
12
    {
13 3
        $class = new ReflectionClass($obj);
14
15 3
        $method = $class->getMethod($name);
16 3
        $method->setAccessible(true);
17
18 3
        return $method->invokeArgs($obj, $args);
19
    }
20
21 4
    public static function getPropertyValue(mixed $obj, string $name): mixed
22
    {
23 4
        $class = new ReflectionClass($obj);
24
25 4
        $property = $class->getProperty($name);
26 4
        $property->setAccessible(true);
27
28 4
        return $property->getValue($obj);
29
    }
30
31 2
    public static function setPropertyValue(mixed $obj, string $name, mixed $value)
32
    {
33 2
        $class = new ReflectionClass($obj);
34
35 2
        $property = $class->getProperty($name);
36 2
        $property->setAccessible(true);
37
38 2
        $property->setValue($obj, $value);
39
    }
40
}
41