Completed
Push — master ( e306f1...c9eaa1 )
by Iman
05: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 3
CRAP Score 1

Importance

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

39
        /** @scrutinizer ignore-call */ 
40
        $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...
40
41
        $mapper = function ($view) {
42 14
            $this->checkViewExists($view);
43 14
        };
44
45 14
        array_walk($views, $mapper);
46
47 13
        return $views;
48
    }
49
50 14
    private function checkViewExists($view)
51
    {
52 14
        if (strpos($view, '*') === false) {
53 12
            view()->getFinder()->find($view);
54
        }
55 13
    }
56
57 13
    private function watchView($view): YouShouldHave
58
    {
59 13
        $this->chain->eventManager = app(ViewEventManager::class)->init($view);
60
61 13
        return app(YouShouldHave::class);
62
    }
63
}
64