Completed
Pull Request — master (#3)
by Rougin
02:59
created

MagicMethodHelper   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 0
loc 27
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A call() 0 15 3
1
<?php
2
3
namespace Rougin\Credo\Helpers;
4
5
/**
6
 * Magic Method Helper
7
 *
8
 * @package Credo
9
 * @author  Rougin Royce Gutib <[email protected]>
10
 */
11
class MagicMethodHelper
12
{
13
    /**
14
     * Calls methods from the specified object in underscore case.
15
     *
16
     * @param  object      $object
17
     * @param  string      $method
18
     * @param  mixed       $parameters
19
     * @param  object|null $anotherObject
20
     * @return mixed
21
     */
22 18
    public static function call($object, $method, $parameters, $anotherObject = null)
23
    {
24 18
        $method = \Doctrine\Common\Util\Inflector::camelize($method);
25 18
        $result = $object;
26
27 18
        if (is_null($anotherObject)) {
28 12
            $anotherObject = $object;
29 12
        }
30
31 18
        if (method_exists($anotherObject, $method)) {
32 18
            $result = call_user_func_array([ $anotherObject, $method ], $parameters);
33 18
        }
34
35 18
        return $result;
36
    }
37
}
38