Completed
Pull Request — master (#22)
by
unknown
02:34
created

PrivateMethodCaller::callMethod()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 1
eloc 5
nc 1
nop 3
1
<?php
2
3
namespace MovingImage\Client\VMPro\Util;
4
5
/**
6
 * Trait PrivateMethodCaller.
7
 *
8
 * @author Robert Szeker <[email protected]>
9
 */
10
trait PrivateMethodCaller
11
{
12
    /**
13
     * Used to call and test private or protected methods from a given object.
14
     *
15
     * @param object $obj
16
     * @param string $methodName
17
     * @param array  $arguments
18
     *
19
     * @return mixed
20
     */
21
    public function callMethod($obj, $methodName, $arguments)
22
    {
23
        $reflector = new \ReflectionObject($obj);
24
        $method = $reflector->getMethod($methodName);
25
        $method->setAccessible(true);
26
27
        return $method->invoke($obj, ...$arguments);
28
    }
29
}
30