AccessesHiddenMethods   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 36
rs 10
c 0
b 0
f 0
wmc 2
lcom 0
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A invokeMethod() 0 8 1
A getProperty() 0 8 1
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