Passed
Push — master ( 3b9db0...fc649a )
by Flo
03:08
created

RestfulController::get()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Faulancer\Controller;
4
5
use Faulancer\Http\JsonResponse;
6
7
/**
8
 * Class RestfulAbstractController
9
 *
10
 * @category REST
11
 * @package  Faulancer\AbstractController
12
 * @author   Florian Knapp <[email protected]>
13
 * @license  MIT License
14
 * @link     Currently no information
15
 * @codeCoverageIgnore
16
 */
17
class RestfulController extends Controller
18
{
19
20
    /**
21
     * GET
22
     *
23
     * @return void
24
     */
25
    public function get()
26
    {
27
    }
28
29
    /**
30
     * POST
31
     *
32
     * @return void
33
     */
34
    public function create()
35
    {
36
    }
37
38
    /**
39
     * UPDATE
40
     *
41
     * @return void
42
     */
43
    public function update()
44
    {
45
    }
46
47
    /**
48
     * DELETE
49
     *
50
     * @return void
51
     */
52
    public function delete()
53
    {
54
    }
55
56
    /**
57
     * Return success response
58
     *
59
     * @param array $data The response data
60
     *
61
     * @return JsonResponse
62
     */
63 View Code Duplication
    protected function success($data = [])
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
64
    {
65
        $response = new JsonResponse();
66
67
        $response->setContent(
68
            [
69
                'success' => true,
70
                'data'    => $data,
71
                'errors'  => []
72
            ]
73
        );
74
75
        $response->setCode(200);
76
77
        return $response;
78
    }
79
80
    /**
81
     * Return erroneous response
82
     *
83
     * @param array $errors The response errors
84
     *
85
     * @return JsonResponse
86
     */
87 View Code Duplication
    protected function error($errors = [])
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
88
    {
89
        $response = new JsonResponse();
90
91
        $response->setContent(
92
            [
93
                'success' => false,
94
                'data'    => [],
95
                'errors'  => $errors
96
            ]
97
        );
98
        $response->setCode(400);
99
100
        return $response;
101
    }
102
103
}