Passed
Push — master ( ec7c3d...8b8c61 )
by Iman
02:56
created

ViewHooks   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 41
rs 10
c 0
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A checkViewExists() 0 4 2
A whenYouSeeViewFile() 0 5 1
A normalizeView() 0 9 1
A whenYouMakeView() 0 3 1
1
<?php
2
3
namespace Imanghafoori\HeyMan\Hooks;
4
5
trait ViewHooks
6
{
7
    /**
8
     * @param array|string $views
9
     * @return \Imanghafoori\HeyMan\YouShouldHave
10
     */
11
    public function whenYouSeeViewFile(...$views)
12
    {
13
        $views = $this->normalizeView($views);
14
15
        return $this->authorize($views);
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

15
        return $this->/** @scrutinizer ignore-call */ authorize($views);
Loading history...
16
    }
17
18
    /**
19
     * @param array|string $views
20
     * @return \Imanghafoori\HeyMan\YouShouldHave
21
     */
22
    public function whenYouMakeView(...$views)
23
    {
24
        return $this->whenYouSeeViewFile(...$views);
25
    }
26
27
    /**
28
     * @param $views
29
     * @return array
30
     */
31
    private function normalizeView(array $views): array
32
    {
33
        $views = $this->normalizeInput($views);
0 ignored issues
show
Bug introduced by
The method normalizeInput() does not exist on Imanghafoori\HeyMan\Hooks\ViewHooks. Did you maybe mean normalizeView()? ( Ignorable by Annotation )

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

33
        /** @scrutinizer ignore-call */ 
34
        $views = $this->normalizeInput($views);

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...
34
        $mapper = function ($view) {
35
            $this->checkViewExists($view);
36
            return 'creating: '.\Illuminate\View\ViewName::normalize($view);
37
        };
38
39
        return array_map($mapper, $views);
40
    }
41
42
    private function checkViewExists($view)
43
    {
44
        if (strpos($view, '*') === false) {
45
            view()->getFinder()->find($view);
46
        }
47
    }
48
}