Completed
Push — master ( 5b8b4e...9f490d )
by Iman
07:14
created

ViewSituations::normalizeView()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 1
dl 0
loc 9
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Imanghafoori\HeyMan\Situations;
4
5
use Imanghafoori\HeyMan\Normilizers\InputNormalizer;
6
use Imanghafoori\HeyMan\WatchingStrategies\ViewEventManager;
7
use Imanghafoori\HeyMan\YouShouldHave;
8
9
class ViewSituations
10
{
11
    use InputNormalizer;
12
    /**
13
     * @param array|string $views
14
     *
15
     * @return YouShouldHave
16
     */
17
    public function whenYouMakeView(...$views): YouShouldHave
18
    {
19
        return $this->watchView($this->normalizeView($views));
20
    }
21
22
    /**
23
     * @param $views
24
     *
25
     * @return array
26
     */
27
    private function normalizeView(array $views): array
28
    {
29
        $views = $this->normalizeInput($views);
30
31
        array_walk($views, function ($view) {
32
            $this->checkViewExists($view);
33
        });
34
35
        return $views;
36
    }
37
38
    private function checkViewExists($view)
39
    {
40
        if (strpos($view, '*') === false) {
41
            view()->getFinder()->find($view);
42
        }
43
    }
44
45
    private function watchView($view): YouShouldHave
46
    {
47
        $this->chain->eventManager = app(ViewEventManager::class)->init($view);
0 ignored issues
show
Bug Best Practice introduced by
The property chain does not exist on Imanghafoori\HeyMan\Situations\ViewSituations. Did you maybe forget to declare it?
Loading history...
48
49
        return app(YouShouldHave::class);
50
    }
51
}