Completed
Push — master ( a05b58...c7a28f )
by Iman
05:22
created

ViewSituations::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 1
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Imanghafoori\HeyMan\Situations;
4
5
use Imanghafoori\HeyMan\Chain;
6
use Imanghafoori\HeyMan\Normilizers\InputNormalizer;
7
use Imanghafoori\HeyMan\WatchingStrategies\ViewEventManager;
8
use Imanghafoori\HeyMan\YouShouldHave;
9
10
class ViewSituations
11
{
12
    use InputNormalizer;
13
14
    private $chain;
15
16
    /**
17
     * HeyMan constructor.
18
     *
19
     * @param Chain $chain
20
     */
21
    public function __construct(Chain $chain)
22
    {
23
        $this->chain = $chain;
24
    }
25
    /**
26
     * @param array|string $views
27
     *
28
     * @return YouShouldHave
29
     */
30
    public function whenYouMakeView(...$views): YouShouldHave
31
    {
32
        return $this->watchView($this->normalizeView($views));
33
    }
34
35
    /**
36
     * @param $views
37
     *
38
     * @return array
39
     */
40
    private function normalizeView(array $views): array
41
    {
42
        $views = $this->normalizeInput($views);
43
44
        array_walk($views, function ($view) {
45
            $this->checkViewExists($view);
46
        });
47
48
        return $views;
49
    }
50
51
    private function checkViewExists($view)
52
    {
53
        if (strpos($view, '*') === false) {
54
            view()->getFinder()->find($view);
55
        }
56
    }
57
58
    private function watchView($view): YouShouldHave
59
    {
60
        $this->chain->eventManager = app(ViewEventManager::class)->init($view);
0 ignored issues
show
Documentation Bug introduced by
It seems like app(Imanghafoori\HeyMan\...er::class)->init($view) of type Imanghafoori\HeyMan\Watc...tegies\ViewEventManager is incompatible with the declared type Imanghafoori\HeyMan\ListenerApplier of property $eventManager.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
61
62
        return app(YouShouldHave::class);
63
    }
64
}
65