Completed
Pull Request — master (#40)
by Iman
08:07 queued 05:12
created

ViewSituations::whenYouMakeView()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
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 19
    public function __construct(Chain $chain)
22
    {
23 19
        $this->chain = $chain;
24 19
    }
25
26
    /**
27
     * @param array|string $views
28
     *
29
     * @return YouShouldHave
30
     */
31 19
    public function whenYouMakeView(...$views): YouShouldHave
32
    {
33 19
        return $this->watchView($this->normalizeView($views));
34
    }
35
36
    /**
37
     * @param $views
38
     *
39
     * @return array
40
     */
41 19
    private function normalizeView(array $views): array
42
    {
43 19
        $views = $this->normalizeInput($views);
44
45
        array_walk($views, function ($view) {
46 19
            $this->checkViewExists($view);
47 19
        });
48
49 18
        return $views;
50
    }
51
52 19
    private function checkViewExists($view)
53
    {
54 19
        if (strpos($view, '*') === false) {
55 17
            view()->getFinder()->find($view);
56
        }
57 18
    }
58
59 18
    private function watchView($view): YouShouldHave
60
    {
61 18
        $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...
62
63 18
        return app(YouShouldHave::class);
64
    }
65
}
66