Completed
Push — api/develop ( 79d127...101612 )
by Bertrand
07:35
created

JobTitlesController::show()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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