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

BladeXComponent   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 33
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A viewModel() 0 14 3
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