Completed
Push — master ( b14ac6...db0d94 )
by Ruben
01:12
created

InvokableControllerEndpointType   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 39
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A make() 0 4 1
A __construct() 0 4 1
A name() 0 6 1
A getEndpoints() 0 4 1
A resolveEndpointType() 0 8 1
1
<?php
2
3
namespace Spatie\LaravelResourceEndpoints\EndpointTypes;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Illuminate\Support\Arr;
7
8
class InvokableControllerEndpointType extends EndpointType
9
{
10
    /** @var string */
11
    private $controller;
12
13
    /** @var string|null */
14
    private $name;
15
16
    public static function make(string $controller): InvokableControllerEndpointType
17
    {
18
        return new InvokableControllerEndpointType($controller);
19
    }
20
21
    public function __construct(string $controller)
22
    {
23
        $this->controller = $controller;
24
    }
25
26
    public function name(?string $name): InvokableControllerEndpointType
27
    {
28
        $this->name = $name;
29
30
        return $this;
31
    }
32
33
    public function getEndpoints(Model $model = null): array
34
    {
35
        return $this->resolveEndpointType()->getEndpoints($model);
36
    }
37
38
    private function resolveEndpointType(): ActionEndpointType
39
    {
40
        return ActionEndpointType::make([$this->controller])
41
            ->name($this->name ?? 'invoke')
42
            ->parameters($this->parameters)
43
            ->prefix($this->prefix)
44
            ->formatter($this->formatter);
45
    }
46
}
47