Passed
Push — master ( 9a0db0...964e1e )
by Pierre
09:22
created

AbstractApi::getParams()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\Reuse\Controllers;
4
5
use App\Interfaces\Controllers\IApi;
6
use App\Container;
7
use App\Http\Request;
8
use App\Http\Response;
9
10
abstract class AbstractApi implements IApi
11
{
12
13
    use \App\Reuse\Controllers\Api\TFileCache;
14
15
    /**
16
     * request
17
     *
18
     * @var Request
19
     */
20
    protected $request;
21
22
    /**
23
     * response
24
     *
25
     * @var Response
26
     */
27
    protected $response;
28
29
    /**
30
     * di container
31
     *
32
     * @var Container
33
     */
34
    private $container;
35
36
    /**
37
     * instanciate
38
     *
39
     */
40 4
    public function __construct(Container $container)
41
    {
42 4
        $this->container = $container;
43 4
        $this->request = $this->getService(\App\Http\Request::class);
44 4
        $this->response = $this->getService(\App\Http\Response::class);
45
    }
46
47
    /**
48
     * preflight CORS with OPTIONS method
49
     *
50
     * @Methods OPTIONS
51
     * @return IApi
52
     */
53 1
    public function preflight(): IApi
54
    {
55 1
        $this->response->setCode(200)->setContent([]);
56 1
        return $this;
57
    }
58
59
    /**
60
     * returns container service from a service name
61
     *
62
     * @param string $serviceName
63
     * @return object
64
     */
65 1
    protected function getService(string $serviceName)
66
    {
67 1
        return $this->container->getService($serviceName);
68
    }
69
70
    /**
71
     * return container instance
72
     *
73
     * @return Container
74
     */
75 1
    protected function getContainer(): Container
76
    {
77 1
        return $this->container;
78
    }
79
80
    /**
81
     * get request instance
82
     *
83
     * @return Request
84
     */
85
    protected function getRequest(): Request
86
    {
87
        return $this->request;
88
    }
89
90
    /**
91
     * get request params
92
     *
93
     * @return array
94
     */
95
    protected function getParams(): array
96
    {
97
        return $this->getRequest()->getParams();
98
    }
99
}
100