Profile   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 51
Duplicated Lines 19.61 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 2
c 0
b 0
f 0
lcom 1
cbo 0
dl 10
loc 51
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A create() 10 10 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
namespace Borfast\Socializr;
4
5
class Profile
6
{
7
    public $provider;
8
    public $id;
9
    public $email;
10
    public $name;
11
    public $first_name;
12
    public $middle_name;
13
    public $last_name;
14
    public $username;
15
    public $link;
16
    public $raw_response;
17
    public $avatar;
18
    public $likes;
19
20
21
    /**
22
     * Create a new Profile object based on an array of attributes and a mapping
23
     * from those attributes to the Profile object's attributes.
24
     * The $mapping array should have this format (example for Facebook):
25
     *
26
     * $mapping = [
27
     *     'id' => 'id',
28
     *     'email' => 'email',
29
     *     'name' => 'name',
30
     *     'first_name' => 'first_name',
31
     *     'middle_name' => 'middle_name',
32
     *     'last_name' => 'last_name',
33
     *     'username' => 'username',
34
     *     'link' => 'link'
35
     * ];
36
     *
37
     * The keys are the name of the Profile object attributes, while the values
38
     * are the key of that attribute in the $attributes array. Like so:
39
     * ['profile_object_attribute' => 'key_in_attributes_array']
40
     *
41
     * @param array $mapping
42
     * @param array $attributes
43
     * @return static
44
     */
45 View Code Duplication
    public static function create(array $mapping, array $attributes)
0 ignored issues
show
Duplication introduced by
This method 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...
46
    {
47
        $profile = new Profile;
48
49
        array_walk($mapping, function (&$name, $key) use (&$profile, &$attributes) {
50
            $profile->$key = (isset($attributes[$name])) ? $attributes[$name] : null;
51
        });
52
53
        return $profile;
54
    }
55
}
56