Passed
Push — master ( 72f46d...eaab0b )
by Iman
06:11
created

Chain::__destruct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 4
c 0
b 0
f 0
nc 2
nop 0
dl 0
loc 7
ccs 5
cts 5
cp 1
crap 2
rs 10
1
<?php
2
3
namespace ImanGhafoori\Terminator;
4
5
class Chain
6
{
7
    protected $data;
8
    protected $method;
9
10
    /**
11
     * Chain constructor.
12
     *
13
     * @param $args
14
     */
15 3
    public function __construct($args, $method)
16
    {
17 3
        $this->data[] = [$args, $method];
18 3
    }
19
20 1
    public function __call($method, $args)
21
    {
22 1
        $this->data[] = [$args, $method];
23 1
        return $this;
24
    }
25
26 3
    public function __destruct()
27
    {
28 3
        $resp = response();
29 3
        foreach ($this->data as $data) {
30 3
            $resp = $resp->{$data[1]}(...$data[0]);
31
        }
32 3
        respondWith($resp);
33
    }
34
}