ScheduleService   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 36
ccs 0
cts 27
cp 0
rs 10
c 0
b 0
f 0
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A find() 0 7 2
A update() 0 7 1
A create() 0 6 1
A getByUserId() 0 3 1
A delete() 0 3 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\Schedule\Services;
10
11
use Modules\Schedule\Contracts\ScheduleServiceContract;
12
use Modules\Schedule\Entities\Schedule;
13
use Modules\Schedule\Events\ScheduleCreatedEvent;
14
use Modules\Schedule\Events\ScheduleUpdatedEvent;
15
16
class ScheduleService implements ScheduleServiceContract
17
{
18
    public function getByUserId($userId)
19
    {
20
        return Schedule::where('user_id', $userId)->get();
21
    }
22
23
    public function find($id): ?Schedule
24
    {
25
        if ($id instanceof Schedule) {
26
            return $id;
27
        }
28
29
        return Schedule::find($id);
0 ignored issues
show
Bug Best Practice introduced by
The expression return Modules\Schedule\...ies\Schedule::find($id) could return the type Illuminate\Database\Eloq...go\Abstracts\MongoModel which includes types incompatible with the type-hinted return Modules\Schedule\Entities\Schedule|null. Consider adding an additional type-check to rule them out.
Loading history...
30
    }
31
32
    public function update($id, $data): Schedule
33
    {
34
        $Schedule = $this->find($id);
35
        $Schedule->update($data);
36
        event(new ScheduleUpdatedEvent($Schedule));
37
38
        return $Schedule;
39
    }
40
41
    public function create($data): Schedule
42
    {
43
        $Schedule = Schedule::create($data);
44
        event(new ScheduleCreatedEvent($Schedule));
45
46
        return $Schedule;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $Schedule returns the type Illuminate\Database\Eloq...go\Abstracts\MongoModel which includes types incompatible with the type-hinted return Modules\Schedule\Entities\Schedule.
Loading history...
47
    }
48
49
    public function delete($id): bool
50
    {
51
        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...
52
    }
53
}
54