InvokeProtectedTrait   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 5
c 1
b 0
f 1
dl 0
loc 18
rs 10
wmc 1

1 Method

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