Sensei_Learner   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 45
Duplicated Lines 20 %

Coupling/Cohesion

Components 0
Dependencies 0
Metric Value
wmc 6
lcom 0
cbo 0
dl 9
loc 45
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B get_full_name() 9 32 6

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
/**
4
 * Responsible for all student specific functionality and helper functions
5
 *
6
 * @package Users
7
 * @author Automattic
8
 *
9
 * @since 1.9.0
10
 */
11
class Sensei_Learner{
12
13
    /**
14
     * Get the students full name
15
     *
16
     * This function replaces Sensei_Learner_Managment->get_learner_full_name
17
     * @since 1.9.0
18
     *
19
     * @param $user_id
20
     * @return bool|mixed|void
21
     */
22
    public static function get_full_name( $user_id ){
23
24
        $full_name = '';
0 ignored issues
show
Unused Code introduced by
$full_name is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
25
26
        if( empty( $user_id ) || ! ( 0 < intval( $user_id ) )
27
            || !( get_userdata( $user_id ) ) ){
28
            return false;
29
        }
30
31
        // get the user details
32
        $user = get_user_by( 'id', $user_id );
33
34 View Code Duplication
        if( ! empty( $user->first_name  ) && ! empty( $user->last_name  )  ){
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...
35
36
            $full_name = trim( $user->first_name   ) . ' ' . trim( $user->last_name  );
37
38
        }else{
39
40
            $full_name =  $user->display_name;
41
42
        }
43
44
        /**
45
         * Filter the user full name from the get_learner_full_name function.
46
         *
47
         * @since 1.8.0
48
         * @param $full_name
49
         * @param $user_id
50
         */
51
        return apply_filters( 'sensei_learner_full_name' , $full_name , $user_id );
52
53
    }// end get_full_name
54
55
}