Test Failed
Push — master ( ecae19...f3c0e1 )
by Iman
05:24
created

Proxy::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 2
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Imanghafoori\Middlewarize;
4
5
class Proxy
6
{
7
    private $obj;
8
9
    private $middlewares;
10
11
    /**
12
     * Chain constructor.
13
     *
14
     * @param $callable
15
     * @param $middlewares
16
     */
17
    public function __construct($callable, $middlewares)
18
    {
19
        $this->obj = $callable;
20
        $this->middlewares = $middlewares;
21
    }
22
23
    public function __call($method, $params)
24
    {
25
        $pipeline = new Pipeline(app());
26
27
        return $pipeline
28
            ->via('handle')
29
            ->send($params)
30
            ->through($this->middlewares)
31
            ->then(function ($params) use ($method) {
32
                return call_user_func_array([$this->obj, $method], $params);
33
            });
34
    }
35
}