Passed
Push — master ( 7bc374...cf39f3 )
by Arthur
05:05
created

MachineService   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 26
ccs 0
cts 12
cp 0
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A update() 0 6 1
A find() 0 3 1
A delete() 0 3 1
A create() 0 6 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\Machine\Services;
10
11
use Modules\Machine\Contracts\MachineServiceContract;
12
use Modules\Machine\Entities\Machine;
13
use Modules\Machine\Events\MachineRegisteredEvent;
14
15
class MachineService implements MachineServiceContract
16
{
17
    public function find($id): ?Machine
18
    {
19
        return Machine::find($id);
0 ignored issues
show
Bug Best Practice introduced by
The expression return Modules\Machine\Entities\Machine::find($id) could return the type Illuminate\Database\Eloquent\Model which includes types incompatible with the type-hinted return null|Modules\Machine\Entities\Machine. Consider adding an additional type-check to rule them out.
Loading history...
20
    }
21
22
    public function update($id, $data): Machine
23
    {
24
        $user = $this->find($id);
25
        $user->update($data);
26
27
        return $user;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $user could return the type null which is incompatible with the type-hinted return Modules\Machine\Entities\Machine. Consider adding an additional type-check to rule them out.
Loading history...
28
    }
29
30
    public function create($data): Machine
31
    {
32
        $machine = Machine::create($data);
33
        event(new MachineRegisteredEvent($machine));
34
35
        return $machine;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $machine could return the type Illuminate\Database\Eloquent\Model which includes types incompatible with the type-hinted return Modules\Machine\Entities\Machine. Consider adding an additional type-check to rule them out.
Loading history...
36
    }
37
38
    public function delete($id): bool
39
    {
40
        return Machine::destroy($id);
0 ignored issues
show
Bug Best Practice introduced by
The expression return Modules\Machine\E...s\Machine::destroy($id) returns the type integer which is incompatible with the type-hinted return boolean.
Loading history...
41
    }
42
}
43