Passed
Push — master ( c13b73...f2713c )
by Arthur
05:06
created

AccountService::getByUserId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: arthur
5
 * Date: 04.10.18
6
 * Time: 16:17.
7
 */
8
9
namespace Modules\Account\Services;
10
11
use Carbon\Carbon;
12
use Modules\Account\Contracts\AccountServiceContract;
13
use Modules\Account\Entities\Account;
14
use Modules\Account\Events\AccountCreatedEvent;
15
use Modules\Account\Events\AccountUpdatedEvent;
16
17
class AccountService implements AccountServiceContract
18
{
19
    public function getByUserId($userId)
20
    {
21
        return Account::where('user_id', $userId)->get();
22
    }
23
24
    public function find($id): ?Account
25
    {
26
        if ($id instanceof Account) {
27
            return $id;
28
        }
29
30
        return Account::find($id);
31
    }
32
33
    public function update($id, $data): Account
34
    {
35
        $Account = $this->find($id);
36
        $Account->update($data);
37
        event(new AccountUpdatedEvent($Account));
38
39
        return $Account;
40
    }
41
42
    public function create($data): Account
43
    {
44
        $Account = Account::create($data);
45
        event(new AccountCreatedEvent($Account));
46
47
        return $Account;
48
    }
49
50
    public function delete($id): bool
51
    {
52
        return Account::destroy($id);
0 ignored issues
show
Bug Best Practice introduced by
The expression return Modules\Account\E...s\Account::destroy($id) returns the type integer which is incompatible with the type-hinted return boolean.
Loading history...
53
    }
54
55
    public function heartbeat($id, $data): void
56
    {
57
        $this->update($id, [
58
            'last_heartbeat' => Carbon::now(),
59
            'online'         => true,
60
        ]);
61
    }
62
}
63