Completed
Pull Request — master (#14)
by Simon
01:56
created

Invoker::invokeMethod()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 3
1
<?php
2
3
namespace SilverLeague\LogViewer\Tests\Helper;
4
5
6
use ReflectionClass;
7
use SilverLeague\LogViewer\Helper\DeprecatedLogFormatter;
8
use SilverStripe\ORM\DataObject;
9
10
/**
11
 * Class Invoker helps by invoking protected or private methods for testing.
12
 * @package SilverLeague\LogViewer\Tests\Helper
13
 *
14
 * @author Simon Erkelens <[email protected]>
15
 */
16
class Invoker
17
{
18
19
    /**
20
     * Call protected/private method of a class.
21
     *
22
     * @param DataObject|DeprecatedLogFormatter &$object Instantiated object that we will run method on.
23
     * @param string $methodName Method name to call
24
     * @param array $parameters Array of parameters to pass into method.
25
     *
26
     * @return mixed Method return.
27
     */
28
    public static function invokeMethod(&$object, $methodName, array $parameters = array())
29
    {
30
        $reflection = new ReflectionClass(get_class($object));
31
        $method = $reflection->getMethod($methodName);
32
        $method->setAccessible(true);
33
34
        return $method->invokeArgs($object, $parameters);
35
    }
36
37
}