Passed
Push — master ( e437b2...21ca17 )
by Iman
08:24
created

ViewHooks::watchView()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
ccs 2
cts 2
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\WatchingStrategies\ViewEventManager;
6
use Imanghafoori\HeyMan\YouShouldHave;
7
8
trait ViewHooks
9
{
10
    /**
11
     * @param array|string $views
12
     *
13
     * @return YouShouldHave
14
     */
15 15
    public function whenYouMakeView(...$views): YouShouldHave
16
    {
17 15
        $views = $this->normalizeView($views);
18
19 14
        return $this->watchView($views);
20
    }
21
22
    /**
23
     * @param $views
24
     *
25
     * @return array
26
     */
27 15
    private function normalizeView(array $views): array
28
    {
29 15
        $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

29
        /** @scrutinizer ignore-call */ 
30
        $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...
30
31
        $mapper = function ($view) {
32
            $this->checkViewExists($view);
33
        };
34
35
        array_walk($views, $mapper);
36
37 15
        return $views;
38
    }
39 15
40
    private function checkViewExists($view)
41
    {
42 15
        if (strpos($view, '*') === false) {
43 15
            view()->getFinder()->find($view);
44
        }
45 15
    }
46
47 14
    private function watchView($view): YouShouldHave
48
    {
49
        $this->chain->eventManager = app(ViewEventManager::class)->init($view);
50 15
51
        return app(YouShouldHave::class);
52 15
    }
53
}
54