Completed
Pull Request — master (#3)
by Rougin
04:33
created

MagicMethodHelper::call()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 15
ccs 10
cts 10
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 8
nc 4
nop 4
crap 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 15
    public static function call($object, $method, $parameters, $anotherObject = null)
23
    {
24 15
        $method = \Doctrine\Common\Util\Inflector::camelize($method);
25 15
        $result = $object;
26
27 15
        if (is_null($anotherObject)) {
28 9
            $anotherObject = $object;
29 9
        }
30
31 15
        if (method_exists($anotherObject, $method)) {
32 15
            $result = call_user_func_array([ $anotherObject, $method ], $parameters);
33 15
        }
34
35 15
        return $result;
36
    }
37
}
38