Completed
Push — master ( 06b292...adafac )
by Nicolai
02:22
created

AccessesHiddenMethods   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 34
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
8
9
/**
10
 * Trait AccessesHiddenMethods
11
 *
12
 * @package SmartWeb\Testing\Util
13
 */
14
trait AccessesHiddenMethods
15
{
16
    
17
    /**
18
     * @param object $object
19
     * @param string $method
20
     * @param array  ...$parameters
21
     *
22
     * @return mixed
23
     */
24
    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...
25
    {
26
        $reflection = new ReflectionClass(get_class($object));
27
        $method = $reflection->getMethod($method);
28
        $method->setAccessible(true);
29
        
30
        return $method->invokeArgs($object, $parameters);
31
    }
32
    
33
    /**
34
     * @param object $object
35
     * @param string $property
36
     *
37
     * @return mixed
38
     */
39
    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...
40
    {
41
        $reflection = new ReflectionClass(get_class($object));
42
        $property = $reflection->getProperty($property);
43
        $property->setAccessible(true);
44
        
45
        return $property->getValue($object);
46
    }
47
}