Completed
Push — master ( 2c64ed...ead60c )
by Ruben
07:32
created

InvokableControllerEndpointType   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

6 Methods

Rating   Name   Duplication   Size   Complexity  
A make() 0 4 1
A __construct() 0 6 1
A name() 0 6 1
A getEndpoints() 0 4 1
A getCollectionEndpoints() 0 4 1
A resolveEndpointType() 0 8 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