Passed
Push — master ( f87abf...70b45d )
by Iman
06:08
created

RouteNormalizer::normalizeUrl()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 1
1
<?php
2
3
namespace Imanghafoori\HeyMan\WatchingStrategies\Routes;
4
5
use Illuminate\Support\Str;
6
7
final class RouteNormalizer
8
{
9
    /**
10
     * @param $actions
11
     *
12
     * @return array
13
     */
14
    public function normalizeAction($actions): array
15
    {
16 10
        $addNamespace = function ($action) {
17 10
            if (Str::startsWith($action, '\\')) {
18 8
                return $action;
19
            }
20
21 2
            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

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