Completed
Push — master ( 834214...ebf38e )
by Ruben
01:35
created

EndpointsCollection::getEndpointTypes()   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 0
1
<?php
2
3
namespace Spatie\LaravelEndpointResources;
4
5
use Illuminate\Support\Collection;
6
use Spatie\LaravelEndpointResources\EndpointTypes\ActionEndpointType;
7
use Spatie\LaravelEndpointResources\EndpointTypes\ControllerEndpointType;
8
use Spatie\LaravelEndpointResources\EndpointTypes\InvokableControllerEndpointType;
9
10
class EndpointsCollection
11
{
12
    /** @var \Illuminate\Support\Collection */
13
    private $endpointTypes;
14
15
    public function __construct()
16
    {
17
        $this->endpointTypes = new Collection();
18
    }
19
20
    public function controller(string $controller): ControllerEndpointType
21
    {
22
        $controllerEndpointType = ControllerEndpointType::make($controller);
23
24
        $this->endpointTypes[] = $controllerEndpointType;
25
26
        return $controllerEndpointType;
27
    }
28
29
    public function invokableController(string $controller): InvokableControllerEndpointType
30
    {
31
        $invokableControllerEndpointType = InvokableControllerEndpointType::make($controller);
32
33
        $this->endpointTypes[] = $invokableControllerEndpointType;
34
35
        return $invokableControllerEndpointType;
36
    }
37
38
    public function action(array $action): ActionEndpointType
39
    {
40
        $actionEndpointType = ActionEndpointType::make($action);
41
42
        $this->endpointTypes[] = $actionEndpointType;
43
44
        return $actionEndpointType;
45
    }
46
47
    public function endpointsCollection(EndpointsCollection $endpointsCollection)
48
    {
49
        $this->endpointTypes = $this->endpointTypes->merge(
50
            $endpointsCollection->getEndpointTypes()
51
        );
52
    }
53
54
    public function getEndpointTypes(): Collection
55
    {
56
        return $this->endpointTypes;
57
    }
58
}
59