Completed
Push — master ( 1e0784...4adfb7 )
by Freek
24s
created

BladeXComponent::viewModel()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.7998
c 0
b 0
f 0
cc 3
nc 3
nop 1
1
<?php
2
3
namespace Spatie\BladeX;
4
5
use Illuminate\Contracts\Support\Arrayable;
6
use Spatie\BladeX\Exceptions\CouldNotRegisterBladeXComponent;
7
8
class BladeXComponent
9
{
10
    /** @var string */
11
    public $name;
12
13
    /** @var string */
14
    public $bladeViewName;
15
16
    /** @var string */
17
    public $viewModelClass;
18
19
    public function __construct(string $name, string $bladeViewName)
20
    {
21
        $this->name = $name;
22
23
        $this->bladeViewName = $bladeViewName;
24
    }
25
26
    public function viewModel(string $viewModelClass)
27
    {
28
        if (! class_exists($viewModelClass)) {
29
            throw CouldNotRegisterBladeXComponent::viewModelNotFound($this->name, $viewModelClass);
30
        }
31
32
        if (! is_a($viewModelClass, Arrayable::class, true)) {
33
            throw CouldNotRegisterBladeXComponent::viewModelNotArrayable($this->name, $viewModelClass);
34
        }
35
36
        $this->viewModelClass = $viewModelClass;
37
38
        return $this;
39
    }
40
}
41