Completed
Push — api/develop ( c699db...24e0a4 )
by Bertrand
14:51
created

ReportsToController   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 228
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
c 1
b 0
f 1
lcom 1
cbo 1
dl 228
loc 228
ccs 10
cts 10
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 5 5 1
A store() 4 4 1
A update() 4 4 1
A destroy() 4 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
/**
4
 * This file is part of the HRis Software package.
5
 *
6
 * HRis - Human Resource and Payroll System
7
 *
8
 * @link http://github.com/HB-Co/HRis
9
 */
10
namespace HRis\Api\Controllers\Profile;
11
12
use HRis\Api\Controllers\BaseController;
13
use HRis\Api\Eloquent\EmployeeSupervisor;
14
use HRis\Api\Eloquent\Employee;
15
use HRis\Api\Requests\Profile\ReportsToRequest;
16
use Swagger\Annotations as SWG;
17
18 View Code Duplication
class ReportsToController extends BaseController
0 ignored issues
show
Duplication introduced by
This class 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...
19
{
20
    /**
21
     * @var Employee
22
     */
23
    protected $employee;
24
25
    /**
26
     * @var EmployeeSupervisor
27
     */
28
    protected $employee_supervisor;
29
30
    /**
31
     * @param Employee            $employee
32
     * @param EmployeeSupervisor  $employee_supervisor
33
     *
34
     * @author Bertrand Kintanar <[email protected]>
35
     */
36 12
    public function __construct(Employee $employee, EmployeeSupervisor $employee_supervisor)
37
    {
38 12
        $this->employee = $employee;
39 12
        $this->employee_supervisor = $employee_supervisor;
40 12
    }
41
42
    /**
43
     * Save the Profile - ReportsTo.
44
     *
45
     * @SWG\Post(
46
     *     path="/profile/supervisors",
47
     *     tags={"Employee Profiles"},
48
     *     consumes={"application/json"},
49
     *     summary="Save the Profile - ReportsTo.",
50
     *     @SWG\Response(response="201", description="Success",
51
     *         @SWG\Schema(
52
     *             title="data",
53
     *             type="object",
54
     *             required={"supervisor", "message", "status_code"},
55
     *             @SWG\Property(property="employee", ref="#/definitions/Employee"),
56
     *             @SWG\Property(property="message", type="string", default="Record successfully added.", description="Status message from server"),
57
     *             @SWG\Property(property="status_code", type="integer", default=201, description="Status code from server"),
58
     *         )
59
     *     ),
60
     *     @SWG\Response(response="400", description="Token not provided",
61
     *         @SWG\Schema(
62
     *             title="data",
63
     *             type="object",
64
     *             required={"message", "status_code", "debug"},
65
     *             @SWG\Property(property="message", type="string", default="Token not provided", description="Error message from server"),
66
     *             @SWG\Property(property="status_code", type="integer", default=400, description="Status code from server"),
67
     *             @SWG\Property(property="debug", type="object", description="Debug back trace"),
68
     *         )
69
     *     ),
70
     *     @SWG\Response(response="422", description="Unable to add record to the database.",
71
     *         @SWG\Schema(
72
     *             title="data",
73
     *             type="object",
74
     *             required={"message", "status_code"},
75
     *             @SWG\Property(property="message", type="string", default="Unable to add record to the database.", description="Status message from server"),
76
     *             @SWG\Property(property="status_code", type="integer", default=422, description="Status code from server"),
77
     *         )
78
     *     ),
79
     *     @SWG\Parameter(
80
     *         name="supervisor",
81
     *         in="body",
82
     *         required=true,
83
     *         @SWG\Property(ref="#/definitions/Employee")
84
     *     ),
85
     *     @SWG\Parameter(
86
     *         name="Authorization",
87
     *         in="header",
88
     *         description="JWT Token",
89
     *         required=true,
90
     *         type="string",
91
     *         default="Bearer "
92
     *     ),
93
     * )
94
     *
95
     * @param ReportsToRequest $request
96
     *
97
     * @return \Dingo\Api\Http\Response
98
     *
99
     * @author Bertrand Kintanar <[email protected]>
100
     */
101 6
    public function store(ReportsToRequest $request)
102
    {
103 6
        return $this->storeModel($request, $this->employee_supervisor, 'supervisor');
104
    }
105
106
    /**
107
     * Update the Profile - ReportsTo.
108
     *
109
     * @SWG\Patch(
110
     *     path="/profile/supervisors",
111
     *     tags={"Employee Profiles"},
112
     *     consumes={"application/json"},
113
     *     summary="Update the Profile - ReportsTo.",
114
     *     @SWG\Response(response="200", description="Success",
115
     *         @SWG\Schema(
116
     *             title="data",
117
     *             type="object",
118
     *             required={"message", "status_code"},
119
     *             @SWG\Property(property="message", type="string", default="Record successfully updated.", description="Status message from server"),
120
     *             @SWG\Property(property="status_code", type="integer", default=200, description="Status code from server"),
121
     *         )
122
     *     ),
123
     *     @SWG\Response(response="400", description="Token not provided",
124
     *         @SWG\Schema(
125
     *             title="data",
126
     *             type="object",
127
     *             required={"message", "status_code", "debug"},
128
     *             @SWG\Property(property="message", type="string", default="Token not provided", description="Error message from server"),
129
     *             @SWG\Property(property="status_code", type="integer", default=400, description="Status code from server"),
130
     *             @SWG\Property(property="debug", type="object", description="Debug back trace"),
131
     *         )
132
     *     ),
133
     *     @SWG\Response(response="404", description="Unable to retrieve record from database.",
134
     *         @SWG\Schema(
135
     *             title="data",
136
     *             type="object",
137
     *             required={"message", "status_code", "debug"},
138
     *             @SWG\Property(property="message", type="string", default="Unable to retrieve record from database.", description="Error message from server"),
139
     *             @SWG\Property(property="status_code", type="integer", default=400, description="Status code from server"),
140
     *             @SWG\Property(property="debug", type="object", description="Debug back trace"),
141
     *         )
142
     *     ),
143
     *     @SWG\Response(response="422", description="Unable to update record.",
144
     *         @SWG\Schema(
145
     *             title="data",
146
     *             type="object",
147
     *             required={"message", "status_code"},
148
     *             @SWG\Property(property="message", type="string", default="Unable to update record.", description="Status message from server"),
149
     *             @SWG\Property(property="status_code", type="integer", default=422, description="Status code from server"),
150
     *         )
151
     *     ),
152
     *     @SWG\Parameter(
153
     *         name="supervisor",
154
     *         in="body",
155
     *         required=true,
156
     *         description="employee's supervisor object that needs to be updated",
157
     *         @SWG\Property(ref="#/definitions/Employee")
158
     *     ),
159
     *     @SWG\Parameter(
160
     *         name="Authorization",
161
     *         in="header",
162
     *         description="JWT Token",
163
     *         required=true,
164
     *         type="string",
165
     *         default="Bearer "
166
     *     ),
167
     * )
168
     *
169
     * @param ReportsToRequest $request
170
     *
171
     * @return \Dingo\Api\Http\Response
172
     *
173
     * @author Bertrand Kintanar <[email protected]>
174
     */
175 4
    public function update(ReportsToRequest $request)
176
    {
177 4
        return $this->updateModel($request, $this->employee_supervisor);
178
    }
179
180
    /**
181
     * Delete the Profile - ReportsTo.
182
     *
183
     * @SWG\Delete(
184
     *     path="/profile/supervisors",
185
     *     tags={"Employee Profiles"},
186
     *     consumes={"application/json"},
187
     *     summary="Delete the Profile - ReportsTo.",
188
     *     @SWG\Response(response="200", description="Success",
189
     *         @SWG\Schema(
190
     *             title="data",
191
     *             type="object",
192
     *             required={"message", "status_code"},
193
     *             @SWG\Property(property="message", type="string", default="Record successfully deleted.", description="Status message from server"),
194
     *             @SWG\Property(property="status_code", type="integer", default=200, description="Status code from server"),
195
     *         )
196
     *     ),
197
     *     @SWG\Response(response="400", description="Token not provided",
198
     *         @SWG\Schema(
199
     *             title="data",
200
     *             type="object",
201
     *             required={"message", "status_code", "debug"},
202
     *             @SWG\Property(property="message", type="string", default="Token not provided", description="Error message from server"),
203
     *             @SWG\Property(property="status_code", type="integer", default=400, description="Status code from server"),
204
     *             @SWG\Property(property="debug", type="object", description="Debug back trace"),
205
     *         )
206
     *     ),
207
     *     @SWG\Response(response="422", description="Unable to delete record from the database.",
208
     *         @SWG\Schema(
209
     *             title="data",
210
     *             type="object",
211
     *             required={"message", "status_code"},
212
     *             @SWG\Property(property="message", type="string", default="Unable to delete record from the database.", description="Status message from server"),
213
     *             @SWG\Property(property="status_code", type="integer", default=422, description="Status code from server"),
214
     *         )
215
     *     ),
216
     *     @SWG\Parameter(
217
     *         name="id",
218
     *         in="formData",
219
     *         description="Employee's supervisor id to be deleted",
220
     *         required=true,
221
     *         type="integer",
222
     *         format="int64",
223
     *         default=1,
224
     *     ),
225
     *     @SWG\Parameter(
226
     *         name="Authorization",
227
     *         in="header",
228
     *         description="JWT Token",
229
     *         required=true,
230
     *         type="string",
231
     *         default="Bearer "
232
     *     ),
233
     * )
234
     *
235
     * @param ReportsToRequest $request
236
     *
237
     * @return \Dingo\Api\Http\Response
238
     *
239
     * @author Bertrand Kintanar <[email protected]>
240
     */
241 4
    public function destroy(ReportsToRequest $request)
242
    {
243 4
        return $this->destroyModel($request, $this->employee_supervisor);
244
    }
245
}
246