Completed
Push — master ( 89a74b...b4fe79 )
by Iman
09:03 queued 05:19
created

Forget::aboutSaving()   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;
4
5
use Imanghafoori\HeyMan\WatchingStrategies\EloquentEventsManager;
6
use Imanghafoori\HeyMan\WatchingStrategies\EventManager;
7
use Imanghafoori\HeyMan\WatchingStrategies\RouterEventManager;
8
use Imanghafoori\HeyMan\WatchingStrategies\ViewEventManager;
9
10
class Forget
11
{
12
    /**
13
     * @param $url
14
     *
15
     * @return array
16
     */
17 13
    private function normalizeInput(array $url): array
18
    {
19 13
        return is_array($url[0]) ? $url[0] : $url;
20
    }
21
22
    /**
23
     * Forget constructor.
24
     */
25 13
    public function __construct()
26
    {
27 13
    }
28
29 4
    public function aboutView(...$view)
30
    {
31 4
        resolve(ViewEventManager::class)->forgetAbout($this->normalizeInput($view));
32 4
    }
33
34 1
    public function aboutSaving(...$model)
35
    {
36 1
        resolve(EloquentEventsManager::class)->forgetAbout($this->normalizeInput($model), 'saving');
37 1
    }
38
39 1
    public function aboutDeleting(...$model)
40
    {
41 1
        resolve(EloquentEventsManager::class)->forgetAbout($this->normalizeInput($model), 'deleting');
42 1
    }
43
44 1
    public function aboutFetching(...$model)
45
    {
46 1
        resolve(EloquentEventsManager::class)->forgetAbout($this->normalizeInput($model), 'retrieved');
47 1
    }
48
49
    public function aboutCreating(...$model)
50
    {
51
        resolve(EloquentEventsManager::class)->forgetAbout($this->normalizeInput($model), 'creating');
52
    }
53
54
    public function aboutUpdating(...$model)
55
    {
56
        resolve(EloquentEventsManager::class)->forgetAbout($this->normalizeInput($model), 'updating');
57
    }
58
59 1
    public function aboutModel(...$model)
60
    {
61 1
        resolve(EloquentEventsManager::class)->forgetAbout($this->normalizeInput($model));
62 1
    }
63
64 2
    public function aboutEvent(...$events)
65
    {
66 2
        resolve(EventManager::class)->forgetAbout($this->normalizeInput($events));
67 2
    }
68
69 1
    public function aboutUrl(...$urls)
70
    {
71 1
        resolve(RouterEventManager::class)->forgetAbout($this->normalizeUrl($urls, 'GET'));
72 1
    }
73
74 1
    public function aboutRoute(...$route)
75
    {
76 1
        resolve(RouterEventManager::class)->forgetAbout($this->normalizeInput($route));
77 1
    }
78
79 1
    public function aboutAction(...$actions)
80
    {
81 1
        resolve(RouterEventManager::class)->forgetAbout($this->normalizeAction($actions));
82 1
    }
83
84
    /**
85
     * @param $url
86
     * @param $verb
87
     *
88
     * @return array
89
     */
90 1
    private function normalizeUrl($url, $verb): array
91
    {
92
        $removeSlash = function ($url) use ($verb) {
93 1
            return $verb.ltrim($url, '/');
94 1
        };
95
96 1
        return array_map($removeSlash, $this->normalizeInput($url));
97
    }
98
99
    /**
100
     * @param $action
101
     *
102
     * @return array
103
     */
104 1
    private function normalizeAction($action): array
105
    {
106
        $addNamespace = function ($action) {
107 1
            if ($action = ltrim($action, '\\')) {
108 1
                return $action;
109
            }
110
111
            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

111
            return app()->/** @scrutinizer ignore-call */ getNamespace().'\\Http\\Controllers\\'.$action;
Loading history...
112 1
        };
113
114 1
        $action = array_map($addNamespace, $this->normalizeInput($action));
115
116 1
        return $action;
117
    }
118
}
119