Completed
Push — api/develop ( 30f124...a43eb8 )
by Bertrand
04:51
created

EmploymentStatusController::update()   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 2
Bugs 0 Features 1
Metric Value
c 2
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 Exception;
13
use HRis\Api\Controllers\BaseController;
14
use HRis\Api\Eloquent\EmploymentStatus;
15
use HRis\Api\Requests\Admin\Job\EmploymentStatusRequest;
16
use Swagger\Annotations as SWG;
17
18
/**
19
 * Class EmploymentStatusController.
20
 */
21 View Code Duplication
class EmploymentStatusController 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...
22
{
23
    /**
24
     * @var EmploymentStatus
25
     */
26
    protected $employment_status;
27
28
    /**
29
     * @param EmploymentStatus $employment_status
30
     *
31
     * @author Bertrand Kintanar <[email protected]>
32
     */
33 14
    public function __construct(EmploymentStatus $employment_status)
34
    {
35 14
        $this->employment_status = $employment_status;
36 14
    }
37
38
    /**
39
     * Delete the Admin - Employment Status.
40
     *
41
     * @SWG\Delete(
42
     *     path="/admin/job/employment-status",
43
     *     tags={"Administration"},
44
     *     consumes={"application/json"},
45
     *     summary="Delete the Admin - Employment Status.",
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="Unable to delete record from the database.",
66
     *         @SWG\Schema(
67
     *             title="data",
68
     *             type="object",
69
     *             required={"message", "status_code"},
70
     *             @SWG\Property(property="message", type="string", default="Unable to delete record from the database.", 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="id",
76
     *         in="formData",
77
     *         description="Employment status 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 EmploymentStatusRequest $request
94
     *
95
     * @return \Dingo\Api\Http\Response
96
     *
97
     * @author Bertrand Kintanar <[email protected]>
98
     */
99 4
    public function destroy(EmploymentStatusRequest $request)
100
    {
101 4
        return $this->_destroy($request, $this->employment_status);
102
    }
103
104
    /**
105
     * Retrieve the Admin - Employment Status.
106
     *
107
     * @SWG\Get(
108
     *     path="/admin/job/employment-status",
109
     *     tags={"Administration"},
110
     *     consumes={"application/json"},
111
     *     summary="Save the Admin - Employment Status.",
112
     *     @SWG\Response(response="200", description="Success",
113
     *         @SWG\Schema(
114
     *             title="data",
115
     *             type="object",
116
     *             required={"data", "table", "message", "status_code"},
117
     *             @SWG\Property(property="data", type="object",
118
     *                 @SWG\Property(property="total", type="integer", default=22),
119
     *                 @SWG\Property(property="per_page", type="integer", default=10),
120
     *                 @SWG\Property(property="current_page", type="integer", default=1),
121
     *                 @SWG\Property(property="last_page", type="integer", default=3),
122
     *                 @SWG\Property(property="next_page_url", type="string", default="https://api.hris.dev/api/admin/job/employment-status?page=2"),
123
     *                 @SWG\Property(property="prev_page_url", type="string", default="null"),
124
     *                 @SWG\Property(property="from", type="integer", default=1),
125
     *                 @SWG\Property(property="to", type="integer", default=10),
126
     *                 @SWG\Property(property="data", type="array",
127
     *                     @SWG\Items(title="employment_status", ref="#/definitions/EmploymentStatus"),
128
     *                 ),
129
     *             ),
130
     *             @SWG\Property(property="table", type="object",
131
     *                 @SWG\Property(property="title", type="string", default="Employment Status"),
132
     *                 @SWG\Property(property="permission", type="string", default="admin.job.employment-status"),
133
     *                 @SWG\Property(property="headers", type="array",
134
     *                     @SWG\Items(title="Id", type="string", default="Id"),
135
     *                 ),
136
     *                 @SWG\Property(property="model", type="object",
137
     *                     @SWG\Property(property="singular", type="string", default="employment_status"),
138
     *                     @SWG\Property(property="plural", type="string", default="employment_statuses"),
139
     *                     @SWG\Property(property="dashed", type="string", default="employment-statuses"),
140
     *                 ),
141
     *                 @SWG\Property(property="data", type="array"),
142
     *             ),
143
     *             @SWG\Property(property="message", type="string", default="Record successfully added.", description="Status message from server"),
144
     *             @SWG\Property(property="status_code", type="integer", default=200, description="Status code from server"),
145
     *         )
146
     *     ),
147
     *     @SWG\Parameter(
148
     *         name="page",
149
     *         in="query",
150
     *         description="Page number for pagination",
151
     *         required=true,
152
     *         type="string",
153
     *         default="1"
154
     *     ),
155
     *     @SWG\Parameter(
156
     *         name="Authorization",
157
     *         in="header",
158
     *         description="JWT Token",
159
     *         required=true,
160
     *         type="string",
161
     *         default="Bearer "
162
     *     ),
163
     * )
164
     *
165
     * @param EmploymentStatusRequest $request
166
     *
167
     * @return \Dingo\Api\Http\Response
168
     *
169
     * @author Bertrand Kintanar <[email protected]>
170
     */
171 2
    public function index(EmploymentStatusRequest $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...
172
    {
173 2
        $employment_statuses = $this->employment_status->paginate(ROWS_PER_PAGE);
0 ignored issues
show
Documentation Bug introduced by
The method paginate does not exist on object<HRis\Api\Eloquent\EmploymentStatus>? 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...
174
175 2
        return $this->_response(200, SUCCESS_RETRIEVE_MESSAGE, ['data' => $employment_statuses, 'table' => $this->setupDataTable($employment_statuses)]);
176
    }
177
178
    /**
179
     * Setup table for employment status.
180
     *
181
     * @param $employment_statuses
182
     *
183
     * @return array
184
     *
185
     * @author Bertrand Kintanar <[email protected]>
186
     */
187 2
    protected function setupDataTable($employment_statuses)
188
    {
189 2
        $table = [];
190
191 2
        $table['title'] = 'Employment Statuses';
192 2
        $table['permission'] = 'admin.job.employment-status';
193 2
        $table['headers'] = ['Id', 'Name'];
194 2
        $table['model'] = [
195 2
            'singular' => 'employment_status',
196 2
            'plural'   => 'employment_statuses',
197 2
            'dashed'   => 'employment-statuses',
198
        ];
199 2
        $table['items'] = $employment_statuses;
200
201 2
        return $table;
202
    }
203
204
    /**
205
     * Save the Admin - Employment Status.
206
     *
207
     * @SWG\Post(
208
     *     path="/admin/job/employment-status",
209
     *     tags={"Administration"},
210
     *     consumes={"application/json"},
211
     *     summary="Save the Admin - Employment Status.",
212
     *     @SWG\Response(response="201", description="Success",
213
     *         @SWG\Schema(
214
     *             title="data",
215
     *             type="object",
216
     *             required={"employment_status", "message", "status_code"},
217
     *             @SWG\Property(property="employment_status", ref="#/definitions/EmploymentStatus"),
218
     *             @SWG\Property(property="message", type="string", default="Record successfully added.", description="Status message from server"),
219
     *             @SWG\Property(property="status_code", type="integer", default=201, description="Status code from server"),
220
     *         )
221
     *     ),
222
     *     @SWG\Response(response="400", description="Token not provided",
223
     *         @SWG\Schema(
224
     *             title="data",
225
     *             type="object",
226
     *             required={"message", "status_code", "debug"},
227
     *             @SWG\Property(property="message", type="string", default="Token not provided", description="Error message from server"),
228
     *             @SWG\Property(property="status_code", type="integer", default=400, description="Status code from server"),
229
     *             @SWG\Property(property="debug", type="object", description="Debug back trace"),
230
     *         )
231
     *     ),
232
     *     @SWG\Response(response="422", description="Unable to add record to the database.",
233
     *         @SWG\Schema(
234
     *             title="data",
235
     *             type="object",
236
     *             required={"message", "status_code"},
237
     *             @SWG\Property(property="message", type="string", default="Unable to add record to the database.", description="Status message from server"),
238
     *             @SWG\Property(property="status_code", type="integer", default=422, description="Status code from server"),
239
     *         )
240
     *     ),
241
     *     @SWG\Parameter(
242
     *         name="employment_status",
243
     *         in="body",
244
     *         required=true,
245
     *         @SWG\Property(ref="#/definitions/EmploymentStatus")
246
     *     ),
247
     *     @SWG\Parameter(
248
     *         name="Authorization",
249
     *         in="header",
250
     *         description="JWT Token",
251
     *         required=true,
252
     *         type="string",
253
     *         default="Bearer "
254
     *     ),
255
     * )
256
     *
257
     * @param EmploymentStatusRequest $request
258
     *
259
     * @return \Dingo\Api\Http\Response
260
     *
261
     * @author Bertrand Kintanar <[email protected]>
262
     */
263 6
    public function store(EmploymentStatusRequest $request)
264
    {
265 6
        return $this->_store($request, $this->employment_status, 'employment_status');
266
    }
267
268
    /**
269
     * Update the Admin - Employment Status.
270
     *
271
     * @SWG\Patch(
272
     *     path="/admin/job/employment-status",
273
     *     tags={"Administration"},
274
     *     consumes={"application/json"},
275
     *     summary="Update the Admin - Employment Status.",
276
     *     @SWG\Response(response="200", description="Success",
277
     *         @SWG\Schema(
278
     *             title="data",
279
     *             type="object",
280
     *             required={"message", "status_code"},
281
     *             @SWG\Property(property="message", type="string", default="Record successfully updated.", 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="Unable to retrieve record from database.",
296
     *         @SWG\Schema(
297
     *             title="data",
298
     *             type="object",
299
     *             required={"message", "status_code", "debug"},
300
     *             @SWG\Property(property="message", type="string", default="Unable to retrieve record from database.", description="Error message from server"),
301
     *             @SWG\Property(property="status_code", type="integer", default=400, description="Status code from server"),
302
     *             @SWG\Property(property="debug", type="object", description="Debug back trace"),
303
     *         )
304
     *     ),
305
     *     @SWG\Response(response="422", description="Unable to update record.",
306
     *         @SWG\Schema(
307
     *             title="data",
308
     *             type="object",
309
     *             required={"message", "status_code"},
310
     *             @SWG\Property(property="message", type="string", default="Unable to update record.", description="Status message from server"),
311
     *             @SWG\Property(property="status_code", type="integer", default=422, description="Status code from server"),
312
     *         )
313
     *     ),
314
     *     @SWG\Parameter(
315
     *         name="employment_status",
316
     *         in="body",
317
     *         required=true,
318
     *         description="employment status object that needs to be updated",
319
     *         @SWG\Property(ref="#/definitions/EmploymentStatus")
320
     *     ),
321
     *     @SWG\Parameter(
322
     *         name="Authorization",
323
     *         in="header",
324
     *         description="JWT Token",
325
     *         required=true,
326
     *         type="string",
327
     *         default="Bearer "
328
     *     ),
329
     * )
330
     *
331
     * @param EmploymentStatusRequest $request
332
     *
333
     * @return \Dingo\Api\Http\Response
334
     *
335
     * @author Bertrand Kintanar <[email protected]>
336
     */
337 4
    public function update(EmploymentStatusRequest $request)
338
    {
339 4
        return $this->_update($request, $this->employment_status, ['name', 'description']);
340
    }
341
}
342