Completed
Pull Request — master (#21)
by Fèvre
04:45 queued 02:13
created

RoleRepository   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 41
Duplicated Lines 31.71 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 13 13 1
A update() 0 9 1

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
namespace Xetaravel\Models\Repositories;
3
4
use Illuminate\Support\Facades\Hash;
5
use Illuminate\Support\Facades\Request as FacadeRequest;
6
use Xetaravel\Models\Role;
7
8
class RoleRepository
9
{
10
    /**
11
     * Create a new user instance after a valid registration.
12
     *
13
     * @param array $data The data used to create the user.
14
     *
15
     * @return \Xetaravel\Models\User
16
     */
17 View Code Duplication
    public static function create(array $data): User
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...
18
    {
19
        $ip = FacadeRequest::ip();
20
21
        return User::create([
22
            'username' => $data['username'],
23
            'email' => $data['email'],
24
            'password' => bcrypt($data['password']),
25
            'register_ip' => $ip,
26
            'last_login_ip' => $ip,
27
            'last_login' => new \DateTime()
28
        ]);
29
    }
30
31
    /**
32
     * Update the role informations after a valid update request.
33
     *
34
     * @param array $data The data used to update the user.
35
     * @param \Xetaravel\Models\Role $role The role to update.
36
     *
37
     * @return bool
38
     */
39
    public static function update(array $data, Role $role): bool
40
    {
41
        $role->name = $data['name'];
42
        $role->description = $data['description'];
43
        $role->css = $data['css'];
44
        $role->level = $data['level'];
45
46
        return $role->save();
47
    }
48
}
49