Total Complexity | 7 |
Total Lines | 45 |
Duplicated Lines | 0 % |
Coverage | 72.72% |
Changes | 0 |
1 | <?php |
||
17 | class MachineService implements MachineServiceContract |
||
18 | { |
||
19 | 5 | public function getByUserId($userId) |
|
20 | { |
||
21 | 5 | return Machine::where('user_id', $userId)->get(); |
|
22 | } |
||
23 | |||
24 | 8 | public function find($id): ?Machine |
|
25 | { |
||
26 | 8 | if ($id instanceof Machine) { |
|
27 | return $id; |
||
28 | } |
||
29 | |||
30 | 8 | return Machine::find($id); |
|
|
|||
31 | } |
||
32 | |||
33 | 1 | public function update($id, $data): Machine |
|
34 | { |
||
35 | 1 | $machine = $this->find($id); |
|
36 | 1 | $machine->update($data); |
|
37 | 1 | event(new MachineUpdatedEvent($machine)); |
|
38 | |||
39 | 1 | return $machine; |
|
40 | } |
||
41 | |||
42 | 1 | public function create($data): Machine |
|
43 | { |
||
44 | 1 | $machine = Machine::create($data); |
|
45 | 1 | event(new MachineRegisteredEvent($machine)); |
|
46 | |||
47 | 1 | return $machine; |
|
48 | } |
||
49 | |||
50 | 1 | public function delete($id): bool |
|
51 | { |
||
52 | 1 | return Machine::destroy($id); |
|
53 | } |
||
54 | |||
55 | public function heartbeat($id, $data): void |
||
62 | ]); |
||
63 | } |
||
64 | } |
||
65 |