Completed
Push — master ( 3c1051...50a607 )
by Iman
09:32
created

EloquentSituations::watchModel()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Imanghafoori\HeyMan\Situations;
4
5
use Imanghafoori\HeyMan\WatchingStrategies\EloquentEventsManager;
6
use Imanghafoori\HeyMan\YouShouldHave;
7
8
class EloquentSituations extends BaseSituation
9
{
10
    /**
11
     * @param mixed ...$model
12
     *
13
     * @return YouShouldHave
14
     */
15
    public function whenYouFetch(...$model)
16
    {
17
        return $this->watchModel('retrieved', $this->normalizeInput($model));
18
    }
19
20
    /**
21
     * @param mixed ...$model
22
     *
23
     * @return YouShouldHave
24
     */
25
    public function whenYouCreate(...$model)
26
    {
27
        return $this->watchModel('creating', $this->normalizeInput($model));
28
    }
29
30
    /**
31
     * @param mixed ...$model
32
     *
33
     * @return YouShouldHave
34
     */
35
    public function whenYouUpdate(...$model)
36
    {
37
        return $this->watchModel('updating', $this->normalizeInput($model));
38
    }
39
40
    /**
41
     * @param mixed ...$model
42
     *
43
     * @return YouShouldHave
44
     */
45
    public function whenYouSave(...$model)
46
    {
47
        return $this->watchModel('saving', $this->normalizeInput($model));
48
    }
49
50
    /**
51
     * @param mixed ...$model
52
     *
53
     * @return YouShouldHave
54
     */
55
    public function whenYouDelete(...$model)
56
    {
57
        return $this->watchModel('deleting', $this->normalizeInput($model));
58
    }
59
60
    private function watchModel($event, $modelClass)
61
    {
62
        $this->chain->eventManager = app(EloquentEventsManager::class)->init($modelClass, $event);
0 ignored issues
show
Documentation Bug introduced by
It seems like app(Imanghafoori\HeyMan\...it($modelClass, $event) of type Imanghafoori\HeyMan\Watc...s\EloquentEventsManager is incompatible with the declared type Imanghafoori\HeyMan\ListenerApplier of property $eventManager.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
63
64
        return app(YouShouldHave::class);
65
    }
66
}