InvokeProtectedTrait::invokeMethod()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 4
c 1
b 0
f 1
nc 1
nop 3
dl 0
loc 7
rs 10
1
<?php
2
3
namespace andmemasin\myabstract\test;
4
5
/**
6
 * Trait InvokeProtectedTrait
7
 * @package andmemasin\myabstract\traits
8
 * @author Tõnis Ormisson <[email protected]>
9
 */
10
trait InvokeProtectedTrait
11
{
12
    /**
13
     * Call protected/private method of a class.
14
     *
15
     * @param object &$object    Instantiated object that we will run method on.
16
     * @param string $methodName Method name to call
17
     * @param array  $parameters Array of parameters to pass into method.
18
     *
19
     * @return mixed Method return.
20
     */
21
    public function invokeMethod(&$object, $methodName, array $parameters = array())
22
    {
23
        $reflection = new \ReflectionClass(get_class($object));
24
        $method = $reflection->getMethod($methodName);
25
        $method->setAccessible(true);
26
27
        return $method->invokeArgs($object, $parameters);
28
    }
29
30
}