Completed
Push — api/develop ( a47469...37f827 )
by Bertrand
49:16 queued 46:18
created

TerminationReasonsController   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 398
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 92.31%

Importance

Changes 5
Bugs 0 Features 1
Metric Value
wmc 7
c 5
b 0
f 1
lcom 1
cbo 1
dl 398
loc 398
ccs 24
cts 26
cp 0.9231
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 4 4 1
A destroy() 4 4 1
A index() 8 8 1
A setupDataTable() 16 16 1
A store() 4 4 1
A show() 4 4 1
A update() 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\PIM\Configuration;
11
12
use HRis\Api\Controllers\BaseController;
13
use HRis\Api\Eloquent\TerminationReason;
14
use HRis\Api\Requests\PIM\Configuration\TerminationReasonRequest;
15
use Swagger\Annotations as SWG;
16
17
/**
18
 * Class TerminationReasonsController.
19
 */
20 View Code Duplication
class TerminationReasonsController 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...
21
{
22
    /**
23
     * @var TerminationReason
24
     */
25
    protected $termination_reason;
26
27
    /**
28
     * @param TerminationReason $termination_reason
29
     *
30
     * @author Bertrand Kintanar <[email protected]>
31
     */
32 12
    public function __construct(TerminationReason $termination_reason)
33
    {
34 12
        $this->termination_reason = $termination_reason;
35 12
    }
36
37
    /**
38
     * Deletes a single instance of Termination Reason.
39
     *
40
     * @SWG\Delete(
41
     *     path="/pim/configuration/termination-reasons/{termination_reason}",
42
     *     description="This route provides the ability to delete a Termination Reason.",
43
     *     tags={"PIM - Configuration"},
44
     *     consumes={"application/json"},
45
     *     summary="Deletes a single instance of Termination Reason.",
46
     *     @SWG\Response(response="200", description="Success",
47
     *         @SWG\Schema(
48
     *             title="data",
49
     *             type="object",
50
     *             required={"message", "status_code"},
51
     *             @SWG\Property(property="message", type="string", default="Record successfully deleted.", description="Status message from server"),
52
     *             @SWG\Property(property="status_code", type="integer", default=200, description="Status code from server"),
53
     *         )
54
     *     ),
55
     *     @SWG\Response(response="400", description="Token not provided",
56
     *         @SWG\Schema(
57
     *             title="data",
58
     *             type="object",
59
     *             required={"message", "status_code", "debug"},
60
     *             @SWG\Property(property="message", type="string", default="Token not provided", description="Error message from server"),
61
     *             @SWG\Property(property="status_code", type="integer", default=400, description="Status code from server"),
62
     *             @SWG\Property(property="debug", type="object", description="Debug back trace"),
63
     *         )
64
     *     ),
65
     *     @SWG\Response(response="422", description="422 Unprocessable Entity",
66
     *         @SWG\Schema(
67
     *             title="data",
68
     *             type="object",
69
     *             required={"message", "status_code"},
70
     *             @SWG\Property(property="message", type="string", default="422 Unprocessable Entity", description="Status message from server"),
71
     *             @SWG\Property(property="status_code", type="integer", default=422, description="Status code from server"),
72
     *         )
73
     *     ),
74
     *     @SWG\Parameter(
75
     *         name="termination_reason",
76
     *         in="path",
77
     *         description="Termination reason id to be deleted",
78
     *         required=true,
79
     *         type="integer",
80
     *         format="int64",
81
     *         default=1,
82
     *     ),
83
     *     @SWG\Parameter(
84
     *         name="Authorization",
85
     *         in="header",
86
     *         description="JWT Token",
87
     *         required=true,
88
     *         type="string",
89
     *         default="Bearer "
90
     *     ),
91
     * )
92
     *
93
     * @param TerminationReason        $termination_reason
94
     * @param TerminationReasonRequest $request
95
     *
96
     * @return \Dingo\Api\Http\Response
97
     *
98
     * @author Bertrand Kintanar <[email protected]>
99
     */
100 2
    public function destroy(TerminationReason $termination_reason, TerminationReasonRequest $request)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
101
    {
102 2
        return $this->destroyModel($termination_reason, $this->termination_reason);
103
    }
104
105
    /**
106
     * Retrieves a paginate aware collection of Termination Reason.
107
     *
108
     * @SWG\Get(
109
     *     path="/pim/configuration/termination-reasons",
110
     *     description="This route provides the ability to retrieve a paginate aware collection of Termination Reasons.",
111
     *     tags={"PIM - Configuration"},
112
     *     consumes={"application/json"},
113
     *     summary="Retrieves a paginate aware collection of Termination Reason.",
114
     *     @SWG\Response(response="200", description="Success",
115
     *         @SWG\Schema(
116
     *             title="data",
117
     *             type="object",
118
     *             required={"data", "table", "message", "status_code"},
119
     *             @SWG\Property(property="data", type="object",
120
     *                 @SWG\Property(property="total", type="integer", default=22),
121
     *                 @SWG\Property(property="per_page", type="integer", default=10),
122
     *                 @SWG\Property(property="current_page", type="integer", default=1),
123
     *                 @SWG\Property(property="last_page", type="integer", default=3),
124
     *                 @SWG\Property(property="next_page_url", type="string", default="https://api.hris.dev/api/pim/configuration/termination-reasons?page=2"),
125
     *                 @SWG\Property(property="prev_page_url", type="string", default="null"),
126
     *                 @SWG\Property(property="from", type="integer", default=1),
127
     *                 @SWG\Property(property="to", type="integer", default=10),
128
     *                 @SWG\Property(property="data", type="array",
129
     *                     @SWG\Items(ref="#/definitions/TerminationReason"),
130
     *                 ),
131
     *             ),
132
     *             @SWG\Property(property="table", type="object",
133
     *                 @SWG\Property(property="title", type="string", default="Termination Reason"),
134
     *                 @SWG\Property(property="permission", type="string", default="pim.configuration.termination-reasons"),
135
     *                 @SWG\Property(property="headers", type="array",
136
     *                     @SWG\Items(title="Id", type="string", default="Id"),
137
     *                 ),
138
     *                 @SWG\Property(property="model", type="object",
139
     *                     @SWG\Property(property="singular", type="string", default="termination_reason"),
140
     *                     @SWG\Property(property="plural", type="string", default="termination_reasons"),
141
     *                     @SWG\Property(property="dashed", type="string", default="termination-reasons"),
142
     *                 ),
143
     *                 @SWG\Property(property="data", type="array",
144
     *                     @SWG\Items(ref="#/definitions/TerminationReason"),
145
     *                 ),
146
     *             ),
147
     *             @SWG\Property(property="message", type="string", default="Record successfully added.", description="Status message from server"),
148
     *             @SWG\Property(property="status_code", type="integer", default=200, description="Status code from server"),
149
     *         )
150
     *     ),
151
     *     @SWG\Parameter(
152
     *         name="page",
153
     *         in="query",
154
     *         description="Page number for pagination",
155
     *         required=true,
156
     *         type="string",
157
     *         default="1"
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 TerminationReasonRequest $request
170
     *
171
     * @return \Dingo\Api\Http\Response
172
     *
173
     * @author Bertrand Kintanar <[email protected]>
174
     */
175 2
    public function index(TerminationReasonRequest $request)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
176
    {
177 2
        $termination_reasons = $this->termination_reason->paginate(ROWS_PER_PAGE);
0 ignored issues
show
Documentation Bug introduced by
The method paginate does not exist on object<HRis\Api\Eloquent\TerminationReason>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
178
179 2
        $data = ['data' => $termination_reasons, 'table' => $this->setupDataTable($termination_reasons)];
180
181 2
        return $this->responseAPI(200, SUCCESS_RETRIEVE_MESSAGE, $data);
182
    }
183
184
    /**
185
     * Setup table for termination reason.
186
     *
187
     * @param $termination_reasons
188
     *
189
     * @return array
190
     *
191
     * @author Bertrand Kintanar <[email protected]>
192
     */
193 2
    protected function setupDataTable($termination_reasons)
194
    {
195 2
        $table = [];
196
197 2
        $table['title'] = 'Termination Reasons';
198 2
        $table['permission'] = 'pim.configuration.termination-reasons';
199 2
        $table['headers'] = ['Id', 'Name'];
200 2
        $table['model'] = [
201 2
            'singular' => 'termination_reason',
202 2
            'plural'   => 'termination_reasons',
203 2
            'dashed'   => 'termination-reasons',
204
        ];
205 2
        $table['items'] = $termination_reasons;
206
207 2
        return $table;
208
    }
209
210
    /**
211
     * Stores a single instance of Termination Reason.
212
     *
213
     * @SWG\Post(
214
     *     path="/pim/configuration/termination-reasons",
215
     *     description="This route provides the ability to store a single instance of Termination Reason.",
216
     *     tags={"PIM - Configuration"},
217
     *     consumes={"application/json"},
218
     *     summary="Stores a single instance of Termination Reason.",
219
     *     @SWG\Response(response="201", description="Success",
220
     *         @SWG\Schema(
221
     *             title="data",
222
     *             type="object",
223
     *             required={"termination_reason", "message", "status_code"},
224
     *             @SWG\Property(property="termination_reason", ref="#/definitions/TerminationReason"),
225
     *             @SWG\Property(property="message", type="string", default="Record successfully added.", description="Status message from server"),
226
     *             @SWG\Property(property="status_code", type="integer", default=201, description="Status code from server"),
227
     *         )
228
     *     ),
229
     *     @SWG\Response(response="400", description="Token not provided",
230
     *         @SWG\Schema(
231
     *             title="data",
232
     *             type="object",
233
     *             required={"message", "status_code", "debug"},
234
     *             @SWG\Property(property="message", type="string", default="Token not provided", description="Error message from server"),
235
     *             @SWG\Property(property="status_code", type="integer", default=400, description="Status code from server"),
236
     *             @SWG\Property(property="debug", type="object", description="Debug back trace"),
237
     *         )
238
     *     ),
239
     *     @SWG\Response(response="422", description="Unable to add record to the database.",
240
     *         @SWG\Schema(
241
     *             title="data",
242
     *             type="object",
243
     *             required={"message", "status_code"},
244
     *             @SWG\Property(property="message", type="string", default="Unable to add record to the database.", description="Status message from server"),
245
     *             @SWG\Property(property="status_code", type="integer", default=422, description="Status code from server"),
246
     *         )
247
     *     ),
248
     *     @SWG\Parameter(
249
     *         name="termination_reason",
250
     *         in="body",
251
     *         required=true,
252
     *         @SWG\Property(ref="#/definitions/TerminationReason")
253
     *     ),
254
     *     @SWG\Parameter(
255
     *         name="Authorization",
256
     *         in="header",
257
     *         description="JWT Token",
258
     *         required=true,
259
     *         type="string",
260
     *         default="Bearer "
261
     *     ),
262
     * )
263
     *
264
     * @param TerminationReasonRequest $request
265
     *
266
     * @return \Dingo\Api\Http\Response
267
     *
268
     * @author Bertrand Kintanar <[email protected]>
269
     */
270 6
    public function store(TerminationReasonRequest $request)
271
    {
272 6
        return $this->storeModel($request, $this->termination_reason, 'termination_reason');
273
    }
274
275
    /**
276
     * Retrieves a single instance of Termination Reason.
277
     *
278
     * @SWG\Get(
279
     *     path="/pim/configuration/termination-reasons/{termination_reason}",
280
     *     description="This route provides the ability to retrieve a single instance of Termination Reason.",
281
     *     tags={"PIM - Configuration"},
282
     *     consumes={"application/json"},
283
     *     summary="Retrieves a single instance of Termination Reason.",
284
     *     @SWG\Response(response="200", description="Success",
285
     *         @SWG\Schema(
286
     *             title="data",
287
     *             type="object",
288
     *             required={"employment_status", "message", "status_code"},
289
     *             @SWG\Property(property="employment_status", ref="#/definitions/TerminationReason"),
290
     *             @SWG\Property(property="message", type="string", default="Record successfully retrieved.", description="Status message from server"),
291
     *             @SWG\Property(property="status_code", type="integer", default=200, description="Status code from server"),
292
     *         )
293
     *     ),
294
     *     @SWG\Response(response="400", description="Token not provided",
295
     *         @SWG\Schema(
296
     *             title="data",
297
     *             type="object",
298
     *             required={"message", "status_code", "debug"},
299
     *             @SWG\Property(property="message", type="string", default="Token not provided", description="Error message from server"),
300
     *             @SWG\Property(property="status_code", type="integer", default=400, description="Status code from server"),
301
     *             @SWG\Property(property="debug", type="object", description="Debug back trace"),
302
     *         )
303
     *     ),
304
     *     @SWG\Response(response="422", description="422 Unprocessable Entity",
305
     *         @SWG\Schema(
306
     *             title="data",
307
     *             type="object",
308
     *             required={"message", "status_code"},
309
     *             @SWG\Property(property="message", type="string", default="422 Unprocessable Entity", description="Status message from server"),
310
     *             @SWG\Property(property="status_code", type="integer", default=422, description="Status code from server"),
311
     *         )
312
     *     ),
313
     *     @SWG\Parameter(
314
     *         name="termination_reason",
315
     *         in="path",
316
     *         description="Termination reason id to be retrieved.",
317
     *         required=true,
318
     *         type="integer",
319
     *         format="int64",
320
     *         default=1,
321
     *     ),
322
     *     @SWG\Parameter(
323
     *         name="Authorization",
324
     *         in="header",
325
     *         description="JWT Token",
326
     *         required=true,
327
     *         type="string",
328
     *         default="Bearer "
329
     *     ),
330
     * )
331
     *
332
     * @param TerminationReason $termination_reason
333
     *
334
     * @return \Dingo\Api\Http\Response
335
     *
336
     * @author Bertrand Kintanar <[email protected]>
337
     */
338
    public function show(TerminationReason $termination_reason)
339
    {
340
        return $this->responseAPI(200, SUCCESS_RETRIEVE_MESSAGE, compact('termination_reason'));
341
    }
342
343
    /**
344
     * Updates a single instance of Termination Reason.
345
     *
346
     * @SWG\Patch(
347
     *     path="/pim/configuration/termination-reasons",
348
     *     description="This route provides the ability to update a single instance of Termination Reason.",
349
     *     tags={"PIM - Configuration"},
350
     *     consumes={"application/json"},
351
     *     summary="Updates a single instance of Termination Reason.",
352
     *     @SWG\Response(response="200", description="Success",
353
     *         @SWG\Schema(
354
     *             title="data",
355
     *             type="object",
356
     *             required={"message", "status_code"},
357
     *             @SWG\Property(property="message", type="string", default="Record successfully updated.", description="Status message from server"),
358
     *             @SWG\Property(property="status_code", type="integer", default=200, description="Status code from server"),
359
     *         )
360
     *     ),
361
     *     @SWG\Response(response="400", description="Token not provided",
362
     *         @SWG\Schema(
363
     *             title="data",
364
     *             type="object",
365
     *             required={"message", "status_code", "debug"},
366
     *             @SWG\Property(property="message", type="string", default="Token not provided", description="Error message from server"),
367
     *             @SWG\Property(property="status_code", type="integer", default=400, description="Status code from server"),
368
     *             @SWG\Property(property="debug", type="object", description="Debug back trace"),
369
     *         )
370
     *     ),
371
     *     @SWG\Response(response="404", description="Unable to retrieve record from database.",
372
     *         @SWG\Schema(
373
     *             title="data",
374
     *             type="object",
375
     *             required={"message", "status_code", "debug"},
376
     *             @SWG\Property(property="message", type="string", default="Unable to retrieve record from database.", description="Error message from server"),
377
     *             @SWG\Property(property="status_code", type="integer", default=400, description="Status code from server"),
378
     *             @SWG\Property(property="debug", type="object", description="Debug back trace"),
379
     *         )
380
     *     ),
381
     *     @SWG\Response(response="422", description="Unable to update record.",
382
     *         @SWG\Schema(
383
     *             title="data",
384
     *             type="object",
385
     *             required={"message", "status_code"},
386
     *             @SWG\Property(property="message", type="string", default="Unable to update record.", description="Status message from server"),
387
     *             @SWG\Property(property="status_code", type="integer", default=422, description="Status code from server"),
388
     *         )
389
     *     ),
390
     *     @SWG\Parameter(
391
     *         name="termination_reason",
392
     *         in="body",
393
     *         required=true,
394
     *         description="termination reason object that needs to be updated",
395
     *         @SWG\Property(ref="#/definitions/TerminationReason")
396
     *     ),
397
     *     @SWG\Parameter(
398
     *         name="Authorization",
399
     *         in="header",
400
     *         description="JWT Token",
401
     *         required=true,
402
     *         type="string",
403
     *         default="Bearer "
404
     *     ),
405
     * )
406
     *
407
     * @param TerminationReasonRequest $request
408
     *
409
     * @return \Dingo\Api\Http\Response
410
     *
411
     * @author Bertrand Kintanar <[email protected]>
412
     */
413 4
    public function update(TerminationReasonRequest $request)
414
    {
415 4
        return $this->updateModel($request, $this->termination_reason);
416
    }
417
}
418