Passed
Push — master ( 848980...7bc374 )
by Arthur
04:30
created

UserService   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 28.57%

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 29
ccs 4
cts 14
cp 0.2857
rs 10
c 0
b 0
f 0
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A newUser() 0 3 1
A delete() 0 3 1
A update() 0 5 1
A find() 0 3 1
A create() 0 5 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: arthur
5
 * Date: 04.10.18
6
 * Time: 16:17.
7
 */
8
9
namespace Modules\User\Services;
10
11
use Modules\User\Contracts\UserServiceContract;
12
use Modules\User\Entities\User;
13
use Modules\User\Events\UserRegisteredEvent;
14
15
class UserService implements UserServiceContract
16
{
17 9
    public function find($id): ?User
18
    {
19 9
        return User::find($id);
0 ignored issues
show
Bug Best Practice introduced by
The expression return Modules\User\Entities\User::find($id) could return the type Illuminate\Database\Eloquent\Collection which is incompatible with the type-hinted return null|Modules\User\Entities\User. Consider adding an additional type-check to rule them out.
Loading history...
20
    }
21
22
    public function update($id, $data): ?User
23
    {
24
        $user = $this->find($id);
25
        $user->update($data);
26
        return $user;
27
    }
28
29
    public function create($data): User
30
    {
31
        $user = User::create($data);
32
        event(new UserRegisteredEvent($user));
33
        return $user;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $user could return the type Illuminate\Database\Eloquent\Model which includes types incompatible with the type-hinted return Modules\User\Entities\User. Consider adding an additional type-check to rule them out.
Loading history...
34
    }
35
36
    public function delete($id): bool
37
    {
38
        return User::destroy($id);
0 ignored issues
show
Bug Best Practice introduced by
The expression return Modules\User\Entities\User::destroy($id) returns the type integer which is incompatible with the type-hinted return boolean.
Loading history...
39
    }
40
41 9
    public function newUser($data): User
42
    {
43 9
        return new User($data);
44
    }
45
46
}
47