AccessesHiddenMethods::getProperty()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 2
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
4
namespace SmartWeb\ModuleTesting\Util;
5
6
use ReflectionClass;
7
use ReflectionException;
8
9
/**
10
 * Trait AccessesHiddenMethods
11
 *
12
 * @package SmartWeb\ModuleTesting\Util
13
 */
14
trait AccessesHiddenMethods
15
{
16
    
17
    /**
18
     * @param object  $object
19
     * @param string  $method
20
     * @param mixed[] ...$parameters
21
     *
22
     * @return mixed
23
     * @throws ReflectionException
24
     */
25
    private function invokeMethod($object, string $method, ...$parameters)
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
26
    {
27
        $reflection = new ReflectionClass(get_class($object));
28
        $method = $reflection->getMethod($method);
29
        $method->setAccessible(true);
30
        
31
        return $method->invokeArgs($object, $parameters);
32
    }
33
    
34
    /**
35
     * @param object $object
36
     * @param string $property
37
     *
38
     * @return mixed
39
     * @throws ReflectionException
40
     */
41
    private function getProperty($object, string $property)
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
42
    {
43
        $reflection = new ReflectionClass(get_class($object));
44
        $property = $reflection->getProperty($property);
45
        $property->setAccessible(true);
46
        
47
        return $property->getValue($object);
48
    }
49
}
50