ClosureViewModel   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 0
dl 0
loc 25
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A withClosure() 0 6 1
A toArray() 0 4 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