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

EndpointsGroup   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 4
dl 0
loc 53
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A controller() 0 12 2
A invokableController() 0 8 1
A action() 0 8 1
A endpointsGroup() 0 6 1
A getEndpointTypes() 0 4 1
1
<?php
2
3
namespace Spatie\LaravelResourceEndpoints;
4
5
use Illuminate\Support\Collection;
6
use Spatie\LaravelResourceEndpoints\EndpointTypes\ActionEndpointType;
7
use Spatie\LaravelResourceEndpoints\EndpointTypes\ControllerEndpointType;
8
use Spatie\LaravelResourceEndpoints\EndpointTypes\InvokableControllerEndpointType;
9
10
class EndpointsGroup
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
        if (method_exists($controller, '__invoke')) {
23
            return $this->invokableController($controller);
24
        }
25
26
        $controllerEndpointType = ControllerEndpointType::make($controller);
27
28
        $this->endpointTypes[] = $controllerEndpointType;
29
30
        return $controllerEndpointType;
31
    }
32
33
    public function invokableController(string $controller): InvokableControllerEndpointType
34
    {
35
        $invokableControllerEndpointType = InvokableControllerEndpointType::make($controller);
36
37
        $this->endpointTypes[] = $invokableControllerEndpointType;
38
39
        return $invokableControllerEndpointType;
40
    }
41
42
    public function action(array $action): ActionEndpointType
43
    {
44
        $actionEndpointType = ActionEndpointType::make($action);
45
46
        $this->endpointTypes[] = $actionEndpointType;
47
48
        return $actionEndpointType;
49
    }
50
51
    public function endpointsGroup(EndpointsGroup $endpointsGroup)
52
    {
53
        $this->endpointTypes = $this->endpointTypes->merge(
54
            $endpointsGroup->getEndpointTypes()
55
        );
56
    }
57
58
    public function getEndpointTypes(): Collection
59
    {
60
        return $this->endpointTypes;
61
    }
62
}
63