Completed
Push — master ( ee9737...268efc )
by Iman
08:18
created

Forget::normalizeUrl()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 2
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Imanghafoori\HeyMan;
4
5
use Imanghafoori\HeyMan\WatchingStrategies\EventManager;
6
use Imanghafoori\HeyMan\WatchingStrategies\RouterEventManager;
7
use Imanghafoori\HeyMan\WatchingStrategies\ViewEventManager;
8
9
class Forget
10
{
11
    /**
12
     * @param $url
13
     *
14
     * @return array
15
     */
16
    private function normalizeInput(array $url): array
17
    {
18
        return is_array($url[0]) ? $url[0] : $url;
19
    }
20
    /**
21
     * Forget constructor.
22
     */
23
    public function __construct()
24
    {
25
    }
26
27
    public function aboutView(...$view)
28
    {
29
        resolve(ViewEventManager::class)->forgetAbout($this->normalizeInput($view));
30
    }
31
32
    public function aboutSaving()
33
    {
34
35
    }
36
37
    public function aboutDeleting()
38
    {
39
40
    }
41
42
    public function aboutCreating()
43
    {
44
45
    }
46
47
    public function aboutUpdating()
48
    {
49
50
    }
51
52
    public function aboutModel()
53
    {
54
55
    }
56
57
58
    public function aboutEvent(...$events)
59
    {
60
        resolve(EventManager::class)->forgetAbout($this->normalizeInput($events));
61
    }
62
63
    public function aboutUrl(...$urls)
64
    {
65
        resolve(RouterEventManager::class)->forgetAbout($this->normalizeUrl($urls, 'GET'));
66
    }
67
68
    public function aboutRoute(...$route)
69
    {
70
        resolve(RouterEventManager::class)->forgetAbout($this->normalizeInput($route));
71
    }
72
73
    public function aboutAction(...$actions)
74
    {
75
        resolve(RouterEventManager::class)->forgetAbout($this->normalizeAction($actions));
76
    }
77
78
    /**
79
     * @param $url
80
     * @param $verb
81
     * @return array
82
     */
83
    private function normalizeUrl($url, $verb): array
84
    {
85
        $removeSlash = function ($url) use ($verb) {
86
            return $verb.ltrim($url, '/');
87
        };
88
89
        return array_map($removeSlash, $this->normalizeInput($url));
90
    }
91
92
    /**
93
     * @param $action
94
     * @return array
95
     */
96
    private function normalizeAction($action): array
97
    {
98
        $addNamespace = function ($action) {
99
            if ($action = ltrim($action, '\\')) {
100
                return $action;
101
            }
102
103
            return app()->getNamespace().'\\Http\\Controllers\\'.$action;
0 ignored issues
show
introduced by
The method getNamespace() does not exist on Illuminate\Container\Container. Are you sure you never get this type here, but always one of the subclasses? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

103
            return app()->/** @scrutinizer ignore-call */ getNamespace().'\\Http\\Controllers\\'.$action;
Loading history...
104
        };
105
106
        $action = array_map($addNamespace, $this->normalizeInput($action));
107
108
        return $action;
109
    }
110
111
}