Completed
Push — master ( b01d16...d9d1e2 )
by Ruben
03:30
created

InvokableControllerEndpointType::getEndpoints()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Spatie\ResourceLinks\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