Passed
Push — master ( 12242c...e9b436 )
by Iman
08:01
created

RouteNormalizer   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 10
dl 0
loc 38
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A normalizeUrl() 0 7 1
A normalizeAction() 0 11 2
A normalizeRoute() 0 3 1
1
<?php
2
3
namespace Imanghafoori\HeyMan\WatchingStrategies\Routes;
4
5
final class RouteNormalizer
6
{
7
    /**
8
     * @param $actions
9
     *
10
     * @return array
11
     */
12
    public function normalizeAction($actions): array
13
    {
14
        $addNamespace = function ($action) {
15
            if ($action = ltrim($action, '\\')) {
16
                return $action;
17
            }
18
19
            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

19
            return app()->/** @scrutinizer ignore-call */ getNamespace().'\\Http\\Controllers\\'.$action;
Loading history...
20
        };
21
22
        return array_map($addNamespace, $actions);
23
    }
24
25
    /**
26
     * @param $urls
27
     * @param $verb
28
     *
29
     * @return array
30
     */
31
    public function normalizeUrl($urls, $verb = 'GET'): array
32
    {
33
        $removeSlash = function ($url) use ($verb) {
34
            return $verb.ltrim($url, '/');
35
        };
36
37
        return array_map($removeSlash, $urls);
38
    }
39
40
    public function normalizeRoute($r)
41
    {
42
        return $r;
43
    }
44
}
45