Completed
Push — master ( ab46c1...42a3a5 )
by Ruben
02:07
created

InvokableControllerEndpointType::getEndpoints()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14

Duplication

Lines 14
Ratio 100 %

Importance

Changes 0
Metric Value
dl 14
loc 14
rs 9.7998
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
namespace Spatie\LaravelEndpointResources\EndpointTypes;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Spatie\LaravelEndpointResources\MultiEndpointType;
7
8
class InvokableControllerEndpointType extends EndpointType implements MultiEndpointType
9
{
10
    /** @var string */
11
    protected $controller;
12
13
    /** @var array */
14
    protected $defaultParameters;
15
16
    public function __construct(string $controller, array $defaultParameters = [])
17
    {
18
        $this->controller = $controller;
19
        $this->defaultParameters = $defaultParameters;
20
    }
21
22 View Code Duplication
    public function getEndpoints(Model $model = null): array
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
23
    {
24
        $endpointType = new ActionEndpointType([$this->controller], $this->defaultParameters);
25
26
        $controller = new $this->controller();
27
28
        $endPointName =  property_exists($controller, 'endPointMethod')
29
            ? $controller->endPointMethod
30
            : 'invoke';
31
32
        $endpointType->setName($endPointName);
33
34
        return $endpointType->getEndpoints($model);
35
    }
36
37 View Code Duplication
    public function getCollectionEndpoints(): array
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
38
    {
39
        $endpointType = new ActionEndpointType([$this->controller], $this->defaultParameters);
40
41
        $controller = new $this->controller();
42
43
        $endPointName =  property_exists($controller, 'collectionEndPointMethod')
44
            ? $controller->collectionEndPointMethod
45
            : 'invoke';
46
47
        $endpointType->setName($endPointName);
48
49
        return $endpointType->getEndpoints();
50
    }
51
}
52