Completed
Push — master ( 29d79e...8aac64 )
by Iman
09:16
created

RouteNormalizer   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Test Coverage

Coverage 90%

Importance

Changes 0
Metric Value
wmc 4
eloc 10
dl 0
loc 38
rs 10
c 0
b 0
f 0
ccs 9
cts 10
cp 0.9

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\Normilizers;
4
5
class RouteNormalizer
6
{
7
    /**
8
     * @param $actions
9
     *
10
     * @return array
11
     */
12 10
    public function normalizeAction($actions): array
13
    {
14
        $addNamespace = function ($action) {
15 10
            if ($action = ltrim($action, '\\')) {
16 10
                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 10
        };
21
22 10
        return array_map($addNamespace, $actions);
23
    }
24
25
    /**
26
     * @param $urls
27
     * @param $verb
28
     *
29
     * @return array
30
     */
31 40
    public function normalizeUrl($urls, $verb = 'GET'): array
32
    {
33
        $removeSlash = function ($url) use ($verb) {
34 40
            return $verb.ltrim($url, '/');
35 40
        };
36
37 40
        return array_map($removeSlash, $urls);
38
    }
39
40
    public function normalizeRoute($r)
41
    {
42
        return $r;
43
    }
44
}
45