MethodAlias::__call()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 4.1755

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 9
c 1
b 0
f 0
nc 4
nop 2
dl 0
loc 15
ccs 7
cts 9
cp 0.7778
crap 4.1755
rs 9.9666
1
<?php
2
namespace Teto\Object;
3
4
/**
5
 * Make Property like method
6
 *
7
 * @author    USAMI Kenta <[email protected]>
8
 * @copyright 2016 Baguette HQ
9
 * @license   http://www.apache.org/licenses/LICENSE-2.0
10
 */
11
trait MethodAlias
12
{
13
    /**
14
     * Call alias method (magic method)
15
     *
16
     * @param  string $name
17
     * @return mixed
18
     * @see    http://php.net/manual/language.oop5.magic.php
19
     * @suppress PhanUndeclaredStaticProperty
20
     */
21 2
    public function __call($name, array $args)
22
    {
23 2
        if (!isset(self::$method_aliases)) {
24
            throw new \LogicException(static::class.'::$method_aliases is not set.');
25
        }
26
27 2
        if (isset(self::$method_aliases[$name])) {
28 1
            $method = self::$method_aliases[$name];
29 1
        } elseif (in_array($name, self::$method_aliases)) {
30
            $method = $name;
31
        } else {
32 1
            throw new \BadMethodCallException(static::class."::{$name}() is not exists.");
33
        }
34
35 1
        return call_user_func([$this, $method]);
36
    }
37
}
38