Passed
Push — master ( 1719b8...ef9411 )
by Iman
02:43
created

EloquentHooks::whenYouCreate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Imanghafoori\HeyMan\Hooks;
4
5
trait EloquentHooks
6
{
7
    /**
8
     * @param mixed ...$model
9
     * @return YouShouldHave
0 ignored issues
show
Bug introduced by
The type Imanghafoori\HeyMan\Hooks\YouShouldHave was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
     */
11
    public function whenYouFetch(...$model)
12
    {
13
        $model = $this->normalizeModel('retrieved', $model);
14
        return $this->authorize($model);
0 ignored issues
show
Bug introduced by
It seems like authorize() 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

14
        return $this->/** @scrutinizer ignore-call */ authorize($model);
Loading history...
15
    }
16
17
    /**
18
     * @param mixed ...$model
19
     * @return YouShouldHave
20
     */
21
    public function whenYouCreate(...$model)
22
    {
23
        $model = $this->normalizeModel('creating', $model);
24
        return $this->authorize($model);
25
    }
26
27
    /**
28
     * @param mixed ...$model
29
     * @return YouShouldHave
30
     */
31
    public function whenYouUpdate(...$model)
32
    {
33
        $model = $this->normalizeModel('updating', $model);
34
        return $this->authorize($model);
35
    }
36
37
    /**
38
     * @param mixed ...$model
39
     * @return YouShouldHave
40
     */
41
    public function whenYouSave(...$model)
42
    {
43
        $model = $this->normalizeModel('saving', $model);
44
        return $this->authorize($model);
45
    }
46
47
    /**
48
     * @param mixed ...$model
49
     * @return YouShouldHave
50
     */
51
    public function whenYouDelete(...$model)
52
    {
53
        $model = $this->normalizeModel('deleting', $model);
54
        return $this->authorize($model);
55
    }
56
    /**
57
     * @param $target
58
     * @param $model
59
     * @return array
60
     */
61
    private function normalizeModel($target, array $model): array
62
    {
63
        $model = $this->normalizeInput($model);
0 ignored issues
show
Bug introduced by
The method normalizeInput() does not exist on Imanghafoori\HeyMan\Hooks\EloquentHooks. Did you maybe mean normalizeModel()? ( Ignorable by Annotation )

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

63
        /** @scrutinizer ignore-call */ 
64
        $model = $this->normalizeInput($model);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
64
        $mapper = function ($model) use ($target) {
65
            return "eloquent.{$target}: {$model}";
66
        };
67
68
        return array_map($mapper, $model);
69
    }
70
}