Completed
Push — master ( ad97e9...f44df5 )
by Iman
01:41
created

Proxy   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 90.91%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 1
dl 0
loc 30
ccs 10
cts 11
cp 0.9091
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A __call() 0 11 1
1
<?php
2
3
namespace Imanghafoori\Middlewarize;
4
5
use Illuminate\Pipeline\Pipeline;
6
7
class Proxy
8
{
9
    private $callable;
10
11
    private $middlewares;
12
13
    /**
14
     * Proxy constructor.
15
     *
16
     * @param $callable
17
     * @param $middlewares
18
     */
19 3
    public function __construct($callable, $middlewares)
20
    {
21 3
        $this->callable = $callable;
22 3
        $this->middlewares = $middlewares;
23 3
    }
24
25 3
    public function __call($method, $params)
26
    {
27 3
        $pipeline = new Pipeline(app());
28
        return $pipeline
29 3
            ->via('handle')
30 3
            ->send($params)
31 3
            ->through($this->middlewares)
32
            ->then((function ($params) use ($method) {
33
               return ($this->$method(...$params));
34 3
            })->bindTo($this->callable, $this->callable));
35
    }
36
}
37