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

EndpointsCollection   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 4
dl 0
loc 49
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A controller() 0 8 1
A invokableController() 0 8 1
A action() 0 8 1
A endpointsCollection() 0 6 1
A getEndpointTypes() 0 4 1
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