Completed
Push — master ( 155303...cc8e8f )
by Tarmo
17s queued 14s
created

Controller   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 25
dl 0
loc 46
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getResource() 0 3 1
A setResponseHandler() 0 6 1
A getResponseHandler() 0 3 1
1
<?php
2
declare(strict_types = 1);
3
/**
4
 * /src/Rest/Controller.php
5
 *
6
 * @author TLe, Tarmo Leppänen <[email protected]>
7
 */
8
9
namespace App\Rest;
10
11
use App\Rest\Interfaces\ControllerInterface;
12
use App\Rest\Interfaces\ResponseHandlerInterface;
13
use App\Rest\Interfaces\RestResourceInterface;
14
use App\Rest\Traits\Actions\RestActionBase;
15
use App\Rest\Traits\RestMethodHelper;
16
use Symfony\Contracts\Service\Attribute\Required;
17
use UnexpectedValueException;
18
19
/**
20
 * Class Controller
21
 *
22
 * @package App\Rest
23
 * @author TLe, Tarmo Leppänen <[email protected]>
24
 *
25
 * @property ?RestResourceInterface $resource
26
 */
27
abstract class Controller implements ControllerInterface
28
{
29
    use RestActionBase;
30
    use RestMethodHelper;
31
32
    public const ACTION_COUNT = 'countAction';
33
    public const ACTION_CREATE = 'createAction';
34
    public const ACTION_DELETE = 'deleteAction';
35
    public const ACTION_FIND = 'findAction';
36
    public const ACTION_FIND_ONE = 'findOneAction';
37
    public const ACTION_IDS = 'idsAction';
38
    public const ACTION_PATCH = 'patchAction';
39
    public const ACTION_UPDATE = 'updateAction';
40
41
    public const METHOD_COUNT = 'countMethod';
42
    public const METHOD_CREATE = 'createMethod';
43
    public const METHOD_DELETE = 'deleteMethod';
44
    public const METHOD_FIND = 'findMethod';
45
    public const METHOD_FIND_ONE = 'findOneMethod';
46
    public const METHOD_IDS = 'idsMethod';
47
    public const METHOD_PATCH = 'patchMethod';
48
    public const METHOD_UPDATE = 'updateMethod';
49
50
    protected ?ResponseHandlerInterface $responseHandler = null;
51
52 431
    public function __construct(
53
        protected readonly RestResourceInterface $resource
54
    ) {
55
    }
56
57 222
    public function getResource(): RestResourceInterface
58
    {
59 222
        return $this->resource ?? throw new UnexpectedValueException('Resource service not set', 500);
60
    }
61
62 167
    public function getResponseHandler(): ResponseHandlerInterface
63
    {
64 167
        return $this->responseHandler ?? throw new UnexpectedValueException('ResponseHandler service not set', 500);
65
    }
66
67 273
    #[Required]
68
    public function setResponseHandler(ResponseHandler $responseHandler): static
69
    {
70 273
        $this->responseHandler = $responseHandler;
71
72 273
        return $this;
73
    }
74
}
75