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

Proxy   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 31
rs 10
c 0
b 0
f 0
wmc 2
lcom 0
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A __call() 0 12 1
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
}