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

EloquentHooks   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 57
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A whenYouSave() 0 3 1
A whenYouFetch() 0 3 1
A watchModel() 0 5 1
A whenYouCreate() 0 3 1
A whenYouUpdate() 0 3 1
A whenYouDelete() 0 3 1
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