UserMapper   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A fromGitterObject() 19 19 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
 * This file is part of GitterBot package.
4
 *
5
 * @author Serafim <[email protected]>
6
 * @date 09.10.2015 16:56
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Interfaces\Gitter;
13
14
use Domains\User;
15
use Interfaces\Gitter\Support\AttributeMapper;
16
17
/**
18
 * Class UserMapper
19
 */
20 View Code Duplication
class UserMapper
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...
21
{
22
    /**
23
     * @param array|\StdClass $attributes
24
     * @return User
25
     * @throws InvalidArgumentException
26
     */
27
    public static function fromGitterObject($attributes)
28
    {
29
        $values = (new AttributeMapper((array) $attributes))
30
            ->rename('id', 'gitter_id')
31
            ->rename('username', 'login')
32
            ->rename('displayName', 'name')
33
            ->rename('avatarUrlMedium', 'avatar')
34
            ->only(['gitter_id', 'login', 'name', 'avatar', 'url'])
35
            ->toArray();
36
37
        $user = User::where('gitter_id', $values['gitter_id'])->first();
38
        if (!$user) {
39
            $user = User::unguarded(function () use ($values) {
40
                return User::create($values);
41
            });
42
        }
43
44
        return $user;
45
    }
46
}
47