Register   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 42
Duplicated Lines 19.05 %

Importance

Changes 0
Metric Value
wmc 2
dl 8
loc 42
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B registerUser() 8 40 2

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
class Register extends \BaseController {
4
5
    public function registerUser() {
6
         $input = Input::only(array(
0 ignored issues
show
Bug introduced by
The type Input was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
             'firstName',
8
             'lastName',
9
            'email',
10
            'password',
11
             'role'
12
        ));
13
14
         
15
        $rules = array(
16
            'firstName'    => 'required|min:4',
17
            'lastName' => 'required|min:4',
18
            'email'    => 'required|email|unique:users',
19
            'password' => 'required|min:4',
20
            'role' => 'required'
21
        );
22
23
        $validator = Validator::make($input, $rules);
24
 $messages = $validator->messages();
0 ignored issues
show
Unused Code introduced by
The assignment to $messages is dead and can be removed.
Loading history...
25 View Code Duplication
        if($validator->fails()) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
26
          
27
            return Response::json(array(
28
                'success' => false,
29
                'errors' => $validator->getMessageBag()->toArray(), 
30
                400
31
                )); // 400 being the HTTP code for an invalid request. 
32
        }
33
       
34
        $id = DB::table('users')->insertGetId(
35
                ['first_name' => Input::get('firstName'),'last_name' => Input::get('lastName'),'email' => Input::get('email'), 'password' => Hash::make(Input::get('password'))]
36
        );
37
        DB::table('user_roles')->insert(
38
                ['user_id' => $id, 'role_id' => Input::get('role')]
39
        );
40
      $channelId=  Hash::make(Input::get('password'));
41
       DB::table('channels')->insert(
42
                ['channel_name' => $channelId, 'author_id' => $id]
43
        );
44
            return View::make('templates/greeting')->with('message', "Account created successfully.You can now log in.Have a great day!");
45
      
46
    }
47
48
   
49
50
}
51
52