Completed
Push — master ( 83945e...947b9c )
by Freek
02:01
created

ClosureViewModel::withClosure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Spatie\BladeX;
4
5
use Closure;
6
use Illuminate\Contracts\Support\Arrayable;
7
8
class ClosureViewModel implements Arrayable
9
{
10
    /** @var callable */
11
    protected $closure;
12
13
    /** @var callable */
14
    protected $arguments;
15
16
    public function __construct(...$arguments)
17
    {
18
        $this->arguments = $arguments[0] ?? [];
19
    }
20
21
    public function withClosure(Closure $closure)
22
    {
23
        $this->closure = $closure;
24
25
        return $this;
26
    }
27
28
    public function toArray(): array
29
    {
30
        return app()->call($this->closure, $this->arguments);
31
    }
32
}
33