Completed
Push — master ( e4a954...682c69 )
by Iman
03:08
created

EloquentHooks::authorizeModel()   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\EloquentConditionApplier;
6
use Imanghafoori\HeyMan\YouShouldHave;
7
8
trait EloquentHooks
9
{
10
    /**
11
     * @param mixed ...$model
12
     *
13
     * @return YouShouldHave
14
     */
15 1
    public function whenYouFetch(...$model)
16
    {
17 1
        $model = $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
        /** @scrutinizer ignore-call */ 
18
        $model = $this->normalizeInput($model);
Loading history...
18
19 1
        return $this->authorizeModel('retrieved', $model);
20
    }
21
22
    /**
23
     * @param mixed ...$model
24
     *
25
     * @return YouShouldHave
26
     */
27 3
    public function whenYouCreate(...$model)
28
    {
29 3
        $model = $this->normalizeInput($model);
30
31 3
        return $this->authorizeModel('creating', $model);
32
    }
33
34
    /**
35
     * @param mixed ...$model
36
     *
37
     * @return YouShouldHave
38
     */
39 2
    public function whenYouUpdate(...$model)
40
    {
41 2
        $model = $this->normalizeInput($model);
42
43 2
        return $this->authorizeModel('updating', $model);
44
    }
45
46
    /**
47
     * @param mixed ...$model
48
     *
49
     * @return YouShouldHave
50
     */
51 3
    public function whenYouSave(...$model)
52
    {
53 3
        $model = $this->normalizeInput($model);
54
55 3
        return $this->authorizeModel('saving', $model);
56
    }
57
58
    /**
59
     * @param mixed ...$model
60
     *
61
     * @return YouShouldHave
62
     */
63 2
    public function whenYouDelete(...$model)
64
    {
65 2
        $model = $this->normalizeInput($model);
66
67 2
        return $this->authorizeModel('deleting', $model);
68
    }
69
70 9
    private function authorizeModel($event, $modelClass)
71
    {
72 9
        $this->authorizer = app(EloquentConditionApplier::class)->init($event, $modelClass);
0 ignored issues
show
Bug Best Practice introduced by
The property authorizer does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
73
74 9
        return app(YouShouldHave::class);
75
    }
76
}
77