Passed
Push — master ( 9234be...3143c1 )
by Arthur
20:30
created

ProxyService::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 3
cp 0
crap 2
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\ProxyRepositoryContract;
13
use Modules\Proxy\Contracts\ProxyServiceContract;
14
use Modules\Proxy\Entities\Proxy;
15
use Modules\Proxy\Events\ProxyCreatedEvent;
16
use Modules\Proxy\Events\ProxyUpdatedEvent;
17
18
class ProxyService implements ProxyServiceContract
19
{
20
    protected $repository;
21
22
    /**
23
     * ProxyService constructor.
24
     * @param $repository
25
     */
26
    public function __construct(ProxyRepositoryContract $repository)
27
    {
28
        $this->repository = $repository;
29
    }
30
31
    public function getByUserId($userId)
32
    {
33
        return Proxy::where('user_id', $userId)->get();
34
    }
35
36
    public function find($id): ?Proxy
37
    {
38
        return $this->repository->resolve($id);
39
    }
40
41
    public function update($id, $data): Proxy
42
    {
43
        $proxy = $this->repository->update($data, $id);
44
        event(new ProxyUpdatedEvent($proxy));
45
46
        return $proxy;
47
    }
48
49
    public function create($data): Proxy
50
    {
51
        $proxy = Proxy::create($data);
52
        event(new ProxyCreatedEvent($proxy));
53
54
        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...
55
    }
56
57
    public function delete($id): bool
58
    {
59
        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...
60
    }
61
62
    public function healthCheck($id, $data): void
63
    {
64
        //TODO DO THE ACTUAL HEALTCHECK
65
        $this->update($id, [
66
            'last_alive_at' => Carbon::now(),
67
            'last_checked_at' => Carbon::now(),
68
        ]);
69
    }
70
}
71