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

ConditionsFacade   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 83.33%

Importance

Changes 0
Metric Value
wmc 7
eloc 13
dl 0
loc 26
ccs 10
cts 12
cp 0.8333
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A define() 0 6 4
A _call() 0 14 3
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