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

Invoker   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 1
lcom 0
cbo 0
dl 0
loc 22
rs 10
c 0
b 0
f 0

1 Method

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