TerminationReasonsController::setupDataTable()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 11

Duplication

Lines 16
Ratio 100 %

Code Coverage

Tests 11
CRAP Score 1

Importance

Changes 0
Metric Value
dl 16
loc 16
ccs 11
cts 11
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 11
nc 1
nop 1
crap 1
1
<?php
2
3
/*
4
 * This file is part of the HRis Software package.
5
 *
6
 * NOTICE OF LICENSE
7
 *
8
 * Licensed under the 3-clause BSD License.
9
 *
10
 * This source file is subject to the 3-clause BSD License that is
11
 * bundled with this package in the LICENSE file.
12
 *
13
 * @version    alpha
14
 *
15
 * @author     Bertrand Kintanar <[email protected]>
16
 * @license    BSD License (3-clause)
17
 * @copyright  (c) 2014-2016, b8 Studios, Ltd
18
 *
19
 * @link       http://github.com/HB-Co/HRis
20
 */
21
22
namespace HRis\Api\Controllers\PIM\Configuration;
23
24
use HRis\Api\Requests\PIM\Configuration\TerminationReasonRequest;
25
use Irradiate\Api\Controllers\BaseController;
26
use Irradiate\Eloquent\TerminationReason;
27
use Swagger\Annotations as SWG;
28
use Symfony\Component\HttpFoundation\Response;
29
30
/**
31
 * Class TerminationReasonsController.
32
 */
33 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...
34
{
35
    /**
36
     * @var TerminationReason
37
     */
38
    protected $termination_reason;
39
40
    /**
41
     * @param TerminationReason $termination_reason
42
     *
43
     * @author Bertrand Kintanar <[email protected]>
44
     */
45 12
    public function __construct(TerminationReason $termination_reason)
46
    {
47 12
        $this->termination_reason = $termination_reason;
48 12
    }
49
50
    /**
51
     * Deletes a single instance of Termination Reason.
52
     *
53
     * @SWG\Delete(
54
     *     path="/pim/configuration/termination-reasons/{termination_reason}",
55
     *     description="This route provides the ability to delete a Termination Reason.",
56
     *     tags={"PIM - Configuration"},
57
     *     consumes={"application/json"},
58
     *     summary="Deletes a single instance of Termination Reason.",
59
     *     @SWG\Response(response="200", description="Success",
60
     *         @SWG\Schema(
61
     *             title="data",
62
     *             type="object",
63
     *             required={"message", "status_code"},
64
     *             @SWG\Property(property="message", type="string", default="Record successfully deleted.", description="Status message from server"),
65
     *             @SWG\Property(property="status_code", type="integer", default=200, description="Status code from server"),
66
     *         )
67
     *     ),
68
     *     @SWG\Response(response="400", description="Token not provided",
69
     *         @SWG\Schema(
70
     *             title="data",
71
     *             type="object",
72
     *             required={"message", "status_code", "debug"},
73
     *             @SWG\Property(property="message", type="string", default="Token not provided", description="Error message from server"),
74
     *             @SWG\Property(property="status_code", type="integer", default=400, description="Status code from server"),
75
     *             @SWG\Property(property="debug", type="object", description="Debug back trace"),
76
     *         )
77
     *     ),
78
     *     @SWG\Response(response="422", description="422 Unprocessable Entity",
79
     *         @SWG\Schema(
80
     *             title="data",
81
     *             type="object",
82
     *             required={"message", "status_code"},
83
     *             @SWG\Property(property="message", type="string", default="422 Unprocessable Entity", description="Status message from server"),
84
     *             @SWG\Property(property="status_code", type="integer", default=422, description="Status code from server"),
85
     *         )
86
     *     ),
87
     *     @SWG\Parameter(
88
     *         name="termination_reason",
89
     *         in="path",
90
     *         description="Termination reason id to be deleted",
91
     *         required=true,
92
     *         type="integer",
93
     *         format="int64",
94
     *         default=1,
95
     *     ),
96
     *     @SWG\Parameter(
97
     *         name="Authorization",
98
     *         in="header",
99
     *         description="JWT Token",
100
     *         required=true,
101
     *         type="string",
102
     *         default="Bearer "
103
     *     ),
104
     * )
105
     *
106
     * @param TerminationReason        $termination_reason
107
     * @param TerminationReasonRequest $request
108
     *
109
     * @return \Dingo\Api\Http\Response
110
     *
111
     * @author Bertrand Kintanar <[email protected]>
112
     */
113 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...
114
    {
115 2
        return $this->destroyModel($termination_reason, $this->termination_reason);
116
    }
117
118
    /**
119
     * Retrieves a paginate aware collection of Termination Reason.
120
     *
121
     * @SWG\Get(
122
     *     path="/pim/configuration/termination-reasons",
123
     *     description="This route provides the ability to retrieve a paginate aware collection of Termination Reasons.",
124
     *     tags={"PIM - Configuration"},
125
     *     consumes={"application/json"},
126
     *     summary="Retrieves a paginate aware collection of Termination Reason.",
127
     *     @SWG\Response(response="200", description="Success",
128
     *         @SWG\Schema(
129
     *             title="data",
130
     *             type="object",
131
     *             required={"data", "table", "message", "status_code"},
132
     *             @SWG\Property(property="data", type="object",
133
     *                 @SWG\Property(property="total", type="integer", default=22),
134
     *                 @SWG\Property(property="per_page", type="integer", default=10),
135
     *                 @SWG\Property(property="current_page", type="integer", default=1),
136
     *                 @SWG\Property(property="last_page", type="integer", default=3),
137
     *                 @SWG\Property(property="next_page_url", type="string", default="https://api.hris.dev/api/pim/configuration/termination-reasons?page=2"),
138
     *                 @SWG\Property(property="prev_page_url", type="string", default="null"),
139
     *                 @SWG\Property(property="from", type="integer", default=1),
140
     *                 @SWG\Property(property="to", type="integer", default=10),
141
     *                 @SWG\Property(property="data", type="array",
142
     *                     @SWG\Items(ref="#/definitions/TerminationReason"),
143
     *                 ),
144
     *             ),
145
     *             @SWG\Property(property="table", type="object",
146
     *                 @SWG\Property(property="title", type="string", default="Termination Reason"),
147
     *                 @SWG\Property(property="permission", type="string", default="pim.configuration.termination-reasons"),
148
     *                 @SWG\Property(property="headers", type="array",
149
     *                     @SWG\Items(title="Id", type="string", default="Id"),
150
     *                 ),
151
     *                 @SWG\Property(property="model", type="object",
152
     *                     @SWG\Property(property="singular", type="string", default="termination_reason"),
153
     *                     @SWG\Property(property="plural", type="string", default="termination_reasons"),
154
     *                     @SWG\Property(property="dashed", type="string", default="termination-reasons"),
155
     *                 ),
156
     *                 @SWG\Property(property="data", type="array",
157
     *                     @SWG\Items(ref="#/definitions/TerminationReason"),
158
     *                 ),
159
     *             ),
160
     *             @SWG\Property(property="message", type="string", default="Record successfully added.", description="Status message from server"),
161
     *             @SWG\Property(property="status_code", type="integer", default=200, description="Status code from server"),
162
     *         )
163
     *     ),
164
     *     @SWG\Parameter(
165
     *         name="page",
166
     *         in="query",
167
     *         description="Page number for pagination",
168
     *         required=true,
169
     *         type="string",
170
     *         default="1"
171
     *     ),
172
     *     @SWG\Parameter(
173
     *         name="Authorization",
174
     *         in="header",
175
     *         description="JWT Token",
176
     *         required=true,
177
     *         type="string",
178
     *         default="Bearer "
179
     *     ),
180
     * )
181
     *
182
     * @param TerminationReasonRequest $request
183
     *
184
     * @return \Dingo\Api\Http\Response
185
     *
186
     * @author Bertrand Kintanar <[email protected]>
187
     */
188 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...
189
    {
190 2
        $termination_reasons = $this->termination_reason->paginate(ROWS_PER_PAGE);
191
192 2
        $data = ['data' => $termination_reasons, 'table' => $this->setupDataTable($termination_reasons)];
193
194 2
        return $this->responseAPI(Response::HTTP_OK, SUCCESS_RETRIEVE_MESSAGE, $data);
195
    }
196
197
    /**
198
     * Setup table for termination reason.
199
     *
200
     * @param $termination_reasons
201
     *
202
     * @return array
203
     *
204
     * @author Bertrand Kintanar <[email protected]>
205
     */
206 2
    protected function setupDataTable($termination_reasons)
207
    {
208 2
        $table = [];
209
210 2
        $table['title'] = 'Termination Reasons';
211 2
        $table['permission'] = 'pim.configuration.termination-reasons';
212 2
        $table['headers'] = ['Id', 'Name'];
213 2
        $table['model'] = [
214 2
            'singular' => 'termination_reason',
215 2
            'plural'   => 'termination_reasons',
216 2
            'dashed'   => 'termination-reasons',
217
        ];
218 2
        $table['items'] = $termination_reasons;
219
220 2
        return $table;
221
    }
222
223
    /**
224
     * Stores a single instance of Termination Reason.
225
     *
226
     * @SWG\Post(
227
     *     path="/pim/configuration/termination-reasons",
228
     *     description="This route provides the ability to store a single instance of Termination Reason.",
229
     *     tags={"PIM - Configuration"},
230
     *     consumes={"application/json"},
231
     *     summary="Stores a single instance of Termination Reason.",
232
     *     @SWG\Response(response="201", description="Success",
233
     *         @SWG\Schema(
234
     *             title="data",
235
     *             type="object",
236
     *             required={"termination_reason", "message", "status_code"},
237
     *             @SWG\Property(property="termination_reason", ref="#/definitions/TerminationReason"),
238
     *             @SWG\Property(property="message", type="string", default="Record successfully added.", description="Status message from server"),
239
     *             @SWG\Property(property="status_code", type="integer", default=201, description="Status code from server"),
240
     *         )
241
     *     ),
242
     *     @SWG\Response(response="400", description="Token not provided",
243
     *         @SWG\Schema(
244
     *             title="data",
245
     *             type="object",
246
     *             required={"message", "status_code", "debug"},
247
     *             @SWG\Property(property="message", type="string", default="Token not provided", description="Error message from server"),
248
     *             @SWG\Property(property="status_code", type="integer", default=400, description="Status code from server"),
249
     *             @SWG\Property(property="debug", type="object", description="Debug back trace"),
250
     *         )
251
     *     ),
252
     *     @SWG\Response(response="422", description="Unable to add record to the database.",
253
     *         @SWG\Schema(
254
     *             title="data",
255
     *             type="object",
256
     *             required={"message", "status_code"},
257
     *             @SWG\Property(property="message", type="string", default="Unable to add record to the database.", description="Status message from server"),
258
     *             @SWG\Property(property="status_code", type="integer", default=422, description="Status code from server"),
259
     *         )
260
     *     ),
261
     *     @SWG\Parameter(
262
     *         name="termination_reason",
263
     *         in="body",
264
     *         required=true,
265
     *         @SWG\Property(ref="#/definitions/TerminationReason")
266
     *     ),
267
     *     @SWG\Parameter(
268
     *         name="Authorization",
269
     *         in="header",
270
     *         description="JWT Token",
271
     *         required=true,
272
     *         type="string",
273
     *         default="Bearer "
274
     *     ),
275
     * )
276
     *
277
     * @param TerminationReasonRequest $request
278
     *
279
     * @return \Dingo\Api\Http\Response
280
     *
281
     * @author Bertrand Kintanar <[email protected]>
282
     */
283 6
    public function store(TerminationReasonRequest $request)
284
    {
285 6
        return $this->storeModel($request, $this->termination_reason, 'termination_reason');
286
    }
287
288
    /**
289
     * Retrieves a single instance of Termination Reason.
290
     *
291
     * @SWG\Get(
292
     *     path="/pim/configuration/termination-reasons/{termination_reason}",
293
     *     description="This route provides the ability to retrieve a single instance of Termination Reason.",
294
     *     tags={"PIM - Configuration"},
295
     *     consumes={"application/json"},
296
     *     summary="Retrieves a single instance of Termination Reason.",
297
     *     @SWG\Response(response="200", description="Success",
298
     *         @SWG\Schema(
299
     *             title="data",
300
     *             type="object",
301
     *             required={"employment_status", "message", "status_code"},
302
     *             @SWG\Property(property="employment_status", ref="#/definitions/TerminationReason"),
303
     *             @SWG\Property(property="message", type="string", default="Record successfully retrieved.", description="Status message from server"),
304
     *             @SWG\Property(property="status_code", type="integer", default=200, description="Status code from server"),
305
     *         )
306
     *     ),
307
     *     @SWG\Response(response="400", description="Token not provided",
308
     *         @SWG\Schema(
309
     *             title="data",
310
     *             type="object",
311
     *             required={"message", "status_code", "debug"},
312
     *             @SWG\Property(property="message", type="string", default="Token not provided", description="Error message from server"),
313
     *             @SWG\Property(property="status_code", type="integer", default=400, description="Status code from server"),
314
     *             @SWG\Property(property="debug", type="object", description="Debug back trace"),
315
     *         )
316
     *     ),
317
     *     @SWG\Response(response="422", description="422 Unprocessable Entity",
318
     *         @SWG\Schema(
319
     *             title="data",
320
     *             type="object",
321
     *             required={"message", "status_code"},
322
     *             @SWG\Property(property="message", type="string", default="422 Unprocessable Entity", description="Status message from server"),
323
     *             @SWG\Property(property="status_code", type="integer", default=422, description="Status code from server"),
324
     *         )
325
     *     ),
326
     *     @SWG\Parameter(
327
     *         name="termination_reason",
328
     *         in="path",
329
     *         description="Termination reason id to be retrieved.",
330
     *         required=true,
331
     *         type="integer",
332
     *         format="int64",
333
     *         default=1,
334
     *     ),
335
     *     @SWG\Parameter(
336
     *         name="Authorization",
337
     *         in="header",
338
     *         description="JWT Token",
339
     *         required=true,
340
     *         type="string",
341
     *         default="Bearer "
342
     *     ),
343
     * )
344
     *
345
     * @param TerminationReason $termination_reason
346
     *
347
     * @return \Dingo\Api\Http\Response
348
     *
349
     * @author Bertrand Kintanar <[email protected]>
350
     */
351
    public function show(TerminationReason $termination_reason)
352
    {
353
        return $this->responseAPI(Response::HTTP_OK, SUCCESS_RETRIEVE_MESSAGE, compact('termination_reason'));
354
    }
355
356
    /**
357
     * Updates a single instance of Termination Reason.
358
     *
359
     * @SWG\Patch(
360
     *     path="/pim/configuration/termination-reasons",
361
     *     description="This route provides the ability to update a single instance of Termination Reason.",
362
     *     tags={"PIM - Configuration"},
363
     *     consumes={"application/json"},
364
     *     summary="Updates a single instance of Termination Reason.",
365
     *     @SWG\Response(response="200", description="Success",
366
     *         @SWG\Schema(
367
     *             title="data",
368
     *             type="object",
369
     *             required={"message", "status_code"},
370
     *             @SWG\Property(property="message", type="string", default="Record successfully updated.", description="Status message from server"),
371
     *             @SWG\Property(property="status_code", type="integer", default=200, description="Status code from server"),
372
     *         )
373
     *     ),
374
     *     @SWG\Response(response="400", description="Token not provided",
375
     *         @SWG\Schema(
376
     *             title="data",
377
     *             type="object",
378
     *             required={"message", "status_code", "debug"},
379
     *             @SWG\Property(property="message", type="string", default="Token not provided", description="Error message from server"),
380
     *             @SWG\Property(property="status_code", type="integer", default=400, description="Status code from server"),
381
     *             @SWG\Property(property="debug", type="object", description="Debug back trace"),
382
     *         )
383
     *     ),
384
     *     @SWG\Response(response="404", description="Unable to retrieve record from database.",
385
     *         @SWG\Schema(
386
     *             title="data",
387
     *             type="object",
388
     *             required={"message", "status_code", "debug"},
389
     *             @SWG\Property(property="message", type="string", default="Unable to retrieve record from database.", description="Error message from server"),
390
     *             @SWG\Property(property="status_code", type="integer", default=400, description="Status code from server"),
391
     *             @SWG\Property(property="debug", type="object", description="Debug back trace"),
392
     *         )
393
     *     ),
394
     *     @SWG\Response(response="422", description="Unable to update record.",
395
     *         @SWG\Schema(
396
     *             title="data",
397
     *             type="object",
398
     *             required={"message", "status_code"},
399
     *             @SWG\Property(property="message", type="string", default="Unable to update record.", description="Status message from server"),
400
     *             @SWG\Property(property="status_code", type="integer", default=422, description="Status code from server"),
401
     *         )
402
     *     ),
403
     *     @SWG\Parameter(
404
     *         name="termination_reason",
405
     *         in="body",
406
     *         required=true,
407
     *         description="termination reason object that needs to be updated",
408
     *         @SWG\Property(ref="#/definitions/TerminationReason")
409
     *     ),
410
     *     @SWG\Parameter(
411
     *         name="Authorization",
412
     *         in="header",
413
     *         description="JWT Token",
414
     *         required=true,
415
     *         type="string",
416
     *         default="Bearer "
417
     *     ),
418
     * )
419
     *
420
     * @param TerminationReasonRequest $request
421
     *
422
     * @return \Dingo\Api\Http\Response
423
     *
424
     * @author Bertrand Kintanar <[email protected]>
425
     */
426 4
    public function update(TerminationReasonRequest $request)
427
    {
428 4
        return $this->updateModel($request, $this->termination_reason);
429
    }
430
}
431