Passed
Push — master ( 139939...b4b8e8 )
by Arthur
21:54 queued 17s
created

ProxyService::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\Proxy\Services;
10
11
use Carbon\Carbon;
12
use Modules\Proxy\Contracts\ProxyServiceContract;
13
use Modules\Proxy\Entities\Proxy;
14
use Modules\Proxy\Events\ProxyCreatedEvent;
15
use Modules\Proxy\Events\ProxyUpdatedEvent;
16
17
class ProxyService implements ProxyServiceContract
18
{
19
    public function getByUserId($userId)
20
    {
21
        return Proxy::where('user_id', $userId)->get();
22
    }
23
24
    public function find($id): ?Proxy
25
    {
26
        if ($id instanceof Proxy) {
27
            return $id;
28
        }
29
30
        return Proxy::find($id);
0 ignored issues
show
Bug Best Practice introduced by
The expression return Modules\Proxy\Entities\Proxy::find($id) could return the type Illuminate\Database\Eloq...go\Abstracts\MongoModel which includes types incompatible with the type-hinted return Modules\Proxy\Entities\Proxy|null. Consider adding an additional type-check to rule them out.
Loading history...
31
    }
32
33
    public function update($id, $data): Proxy
34
    {
35
        $proxy = $this->find($id);
36
        $proxy->update($data);
37
        event(new ProxyUpdatedEvent($proxy));
38
39
        return $proxy;
40
    }
41
42
    public function create($data): Proxy
43
    {
44
        $proxy = Proxy::create($data);
45
        event(new ProxyCreatedEvent($proxy));
46
47
        return $proxy;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $proxy returns the type Illuminate\Database\Eloq...go\Abstracts\MongoModel which includes types incompatible with the type-hinted return Modules\Proxy\Entities\Proxy.
Loading history...
48
    }
49
50
    public function delete($id): bool
51
    {
52
        return $this->find($id)->delete();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->find($id)->delete() could return the type null which is incompatible with the type-hinted return boolean. Consider adding an additional type-check to rule them out.
Loading history...
53
    }
54
55
    public function healthCheck($id, $data): void
56
    {
57
        //TODO DO THE ACTUAL HEALTCHECK
58
        $this->update($id, [
59
            'last_alive_at' => Carbon::now(),
60
            'last_checked_at'         => Carbon::now(),
61
        ]);
62
    }
63
}
64