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

RoleRepository::update()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 2
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