Passed
Push — master ( 2ef3c3...2a4402 )
by Iman
03:41
created

EloquentHooks::watchModel()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Imanghafoori\HeyMan\Hooks;
4
5
use Imanghafoori\HeyMan\WatchingStrategies\EloquentEventsManager;
6
use Imanghafoori\HeyMan\YouShouldHave;
7
8
trait EloquentHooks
9
{
10
    /**
11
     * @param mixed ...$model
12
     *
13
     * @return YouShouldHave
14
     */
15 5
    public function whenYouFetch(...$model)
16
    {
17 5
        return $this->watchModel('retrieved', $this->normalizeInput($model));
0 ignored issues
show
Bug introduced by
It seems like normalizeInput() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

17
        return $this->watchModel('retrieved', $this->/** @scrutinizer ignore-call */ normalizeInput($model));
Loading history...
18
    }
19
20
    /**
21
     * @param mixed ...$model
22
     *
23
     * @return YouShouldHave
24
     */
25 6
    public function whenYouCreate(...$model)
26
    {
27 6
        return $this->watchModel('creating', $this->normalizeInput($model));
28
    }
29
30
    /**
31
     * @param mixed ...$model
32
     *
33
     * @return YouShouldHave
34
     */
35 2
    public function whenYouUpdate(...$model)
36
    {
37 2
        return $this->watchModel('updating', $this->normalizeInput($model));
38
    }
39
40
    /**
41
     * @param mixed ...$model
42
     *
43
     * @return YouShouldHave
44
     */
45 4
    public function whenYouSave(...$model)
46
    {
47 4
        return $this->watchModel('saving', $this->normalizeInput($model));
48
    }
49
50
    /**
51
     * @param mixed ...$model
52
     *
53
     * @return YouShouldHave
54
     */
55 3
    public function whenYouDelete(...$model)
56
    {
57 3
        return $this->watchModel('deleting', $this->normalizeInput($model));
58
    }
59
60 15
    private function watchModel($event, $modelClass)
61
    {
62 15
        $this->chain->eventManager = app(EloquentEventsManager::class)->init($modelClass, $event);
63
64 15
        return app(YouShouldHave::class);
65
    }
66
}
67