Code Duplication    Length = 11-13 lines in 3 locations

src/Http/Api/ModuleController.php 1 location

@@ 110-120 (lines=11) @@
107
        }
108
109
        $name = $request->input('name');
110
        if (isset($name)) {
111
            if (!$name) {
112
                throw new \UnexpectedValueException('the name can not be empty.', -11400);
113
            }
114
            if ($module->name !== $name && Module::whereRaw([ 'name' => $name ])->exists()) {
115
                throw new \UnexpectedValueException('module name cannot be repeated', -11401);
116
            }
117
        }
118
119
        $principal_id = $request->input('principal');
120
        if (isset($principal_id)) {
121
            if ($principal_id) {
122
                $user_info = Sentinel::findById($principal_id);
123
                $principal = [ 'id' => $principal_id, 'name' => $user_info->first_name ];

src/Http/Api/UserController.php 1 location

@@ 301-313 (lines=13) @@
298
        }
299
300
        $email = $request->input('email');
301
        if (isset($email)) {
302
            if (!$email) {
303
                throw new \UnexpectedValueException('the email can not be empty.', -10101);
304
            }
305
            if ($user = Sentinel::findByCredentials([ 'email' => $email ])) {
306
                if ($user->id !== $id) {
307
                    throw new \InvalidArgumentException('email has already existed.', -10102);
308
                }
309
            }
310
        }
311
312
        $user = Sentinel::findById($id);
313
        if (!$user) {
314
            throw new \UnexpectedValueException('the user does not exist.', -10106);
315
        }
316
        if (isset($user->diectory) && $user->directory && $user->diectory != 'self') {

src/Http/Api/VersionController.php 1 location

@@ 216-227 (lines=12) @@
213
        }
214
215
        $name = $request->input('name');
216
        if (isset($name)) {
217
            if (!$name) {
218
                throw new \UnexpectedValueException('the name can not be empty.', -11500);
219
            }
220
221
            if ($version->name !== $name && Version::whereRaw([ 'name' => $name, 'project_key' => $project_key ])->exists()) {
222
                throw new \UnexpectedValueException('version name cannot be repeated', -11501);
223
            }
224
        }
225
226
        $start_time = $request->input('start_time') ? $request->input('start_time') : $version->start_time;
227
        $end_time = $request->input('end_time') ? $request->input('end_time') : $version->end_time;
228
        if ($start_time > $end_time) {
229
            throw new \UnexpectedValueException('start-time must be less then end-time', -11502);
230
        }