Completed
Push — master ( 2c64ed...ead60c )
by Ruben
07:32
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\LaravelResourceEndpoints\EndpointTypes;
4
5
use Illuminate\Database\Eloquent\Model;
6
7
class InvokableControllerEndpointType extends ControllerEndpointType
8
{
9
    /** @var string */
10
    private $controller;
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
11
12
    /** @var string|null */
13
    private $name;
14
15
    public static function make(string $controller): ControllerEndpointType
16
    {
17
        return new InvokableControllerEndpointType($controller);
18
    }
19
20
    public function __construct(string $controller)
21
    {
22
        parent::__construct($controller);
23
24
        $this->controller = $controller;
25
    }
26
27
    public function name(?string $name): InvokableControllerEndpointType
28
    {
29
        $this->name = $name;
30
31
        return $this;
32
    }
33
34
    public function getEndpoints(Model $model = null): array
35
    {
36
        return $this->resolveEndpointType()->getEndpoints($model);
37
    }
38
39
    public function getCollectionEndpoints(): array
40
    {
41
        return $this->resolveEndpointType()->getEndpoints();
42
    }
43
44
    private function resolveEndpointType(): ActionEndpointType
45
    {
46
        return ActionEndpointType::make([$this->controller])
47
            ->name($this->name ?? 'invoke')
48
            ->parameters($this->parameters)
49
            ->prefix($this->prefix)
50
            ->formatter($this->formatter);
51
    }
52
}
53