Conditions | 4 |
Paths | 4 |
Total Lines | 30 |
Code Lines | 19 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 20 |
Changes | 2 | ||
Bugs | 0 | Features | 1 |
1 | <?php |
||
28 | public function __construct($route, $paystackObj) |
||
29 | { |
||
30 | $this->route = strtolower($route); |
||
31 | $this->route_class = 'Yabacon\\Paystack\\Routes\\' . ucwords($route); |
||
32 | |||
33 | $mets = get_class_methods($this->route_class); |
||
34 | if (empty($mets)) { |
||
35 | throw new \InvalidArgumentException('Class "' . $this->route . '" does not exist.'); |
||
36 | } |
||
37 | // add methods to this object per method, except root |
||
38 | foreach ($mets as $mtd) { |
||
39 | if ($mtd === 'root') { |
||
40 | // skip root method |
||
41 | continue; |
||
42 | } |
||
43 | $mtdFunc = function ( |
||
44 | array $params = [ ], |
||
45 | array $sentargs = [ ] |
||
46 | ) use ( |
||
47 | $mtd, |
||
48 | $paystackObj |
||
49 | ) { |
||
50 | $interface = call_user_func($this->route_class . '::' . $mtd); |
||
51 | // TODO: validate params and sentargs against definitions |
||
52 | $caller = new Caller($paystackObj); |
||
53 | return $caller->callEndpoint($interface, $params, $sentargs); |
||
54 | }; |
||
55 | $this->methods[$mtd] = \Closure::bind($mtdFunc, $this, get_class()); |
||
56 | } |
||
57 | } |
||
58 | } |
||
59 |