Completed
Push — master ( a8911c...bd4d74 )
by Iman
02:29
created

ConditionsFacade::_call()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3.0175

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 14
ccs 7
cts 8
cp 0.875
rs 10
c 0
b 0
f 0
cc 3
nc 3
nop 2
crap 3.0175
1
<?php
2
3
namespace Imanghafoori\HeyMan\Conditions;
4
5
class ConditionsFacade
6
{
7
    private $methods = [];
8
9 100
    public function _call($method, $param)
10
    {
11 100
        if (! isset($this->methods[$method])) {
12
            throw new \BadMethodCallException($method.' does not exists as a Heyman condition');
13
        }
14 100
        $condition = $this->methods[$method];
15
16 100
        if (is_callable($condition)) {
17 1
            return $condition(...$param);
18
        }
19
20 99
        list($class, $method) = explode('@', $condition);
21
22 99
        return call_user_func_array([new $class, $method], $param);
23
    }
24
25 110
    public function define($methodName, $callable)
26
    {
27 110
        if (is_callable($callable) || (is_string($callable) and mb_strpos($callable, '@'))) {
28 110
            $this->methods[$methodName] = $callable;
29
        } else {
30
            throw new \InvalidArgumentException("$callable should be string Class@method or a php callable");
31
        }
32 110
    }
33
}
34