Completed
Push — master ( 3cf2a3...b96e1a )
by Pierre
02:31 queued 12s
created

Restful::update()   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 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
1
<?php
2
3
namespace App\Controllers\Api\V1;
4
5
use App\Interfaces\Controllers\IApi;
6
use App\Reuse\Controllers\AbstractApi;
7
use App\Http\Response;
8
use App\Container;
9
10
final class Restful extends AbstractApi implements IApi
11
{
12
13
    /**
14
     * instanciate
15
     *
16
     * @param Container $container
17
     */
18
    public function __construct(Container $container)
19
    {
20
        parent::__construct($container);
21
    }
22
23
    /**
24
     * index
25
     *
26
     * @Request.method GET
27
     * @return Restful
28
     */
29
    final public function index(): Restful
30
    {
31
        return $this->setResponse(__CLASS__, __FUNCTION__);
32
    }
33
34
    /**
35
     * store
36
     *
37
     * @Request.method POST
38
     * @return Restful
39
     */
40
    final public function store(): Restful
41
    {
42
        return $this->setResponse(__CLASS__, __FUNCTION__);
43
    }
44
45
    /**
46
     * update
47
     *
48
     * @Request.method PUT/PATCH
49
     * @return Restful
50
     */
51
    final public function update(): Restful
52
    {
53
        return $this->setResponse(__CLASS__, __FUNCTION__);
54
    }
55
56
    /**
57
     * delete
58
     *
59
     * @Request.method DELETE
60
     * @return Restful
61
     */
62
    final public function delete(): Restful
63
    {
64
        return $this->setResponse(__CLASS__, __FUNCTION__);
65
    }
66
67
    /**
68
     * set response with for a classname and action
69
     *
70
     * @param string $classname
71
     * @param string $action
72
     * @return Restful
73
     */
74
    protected function setResponse(string $classname, string $action): Restful
75
    {
76
        $this->response
77
            ->setCode(Response::HTTP_OK)
78
            ->setContent(
79
                [
80
                    'error' => false,
81
                    'datas' => [
82
                        'method' => $this->request->getMethod(),
83
                        'params' => $this->request->getParams(),
84
                        'controller' => $classname,
85
                        'action' => $action,
86
                    ]
87
                ]
88
            );
89
        return $this;
90
    }
91
}
92