UrlResolver::resolveCommandLine()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 4
c 0
b 0
f 0
nc 2
nop 0
dl 0
loc 8
ccs 4
cts 4
cp 1
crap 2
rs 10
1
<?php
2
3
namespace OwenIt\Auditing\Resolvers;
4
5
use Illuminate\Support\Facades\App;
6
use Illuminate\Support\Facades\Request;
7
use OwenIt\Auditing\Contracts\Auditable;
8
use OwenIt\Auditing\Contracts\Resolver;
9
10
class UrlResolver implements Resolver
11
{
12
    public static function resolve(Auditable $auditable): string
13
    {
14 15
        if (! empty($auditable->preloadedResolverData['url'] ?? null)) {
0 ignored issues
show
Bug introduced by
Accessing preloadedResolverData on the interface OwenIt\Auditing\Contracts\Auditable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
15
            return $auditable->preloadedResolverData['url'] ?? '';
16 15
        }
17 15
18
        if (App::runningInConsole()) {
19
            return self::resolveCommandLine();
20 15
        }
21 13
22
        return Request::fullUrl();
23
    }
24 2
25
    public static function resolveCommandLine(): string
26
    {
27 13
        $command = Request::server('argv', null);
28
        if (is_array($command)) {
29 13
            return implode(' ', $command);
30 13
        }
31 13
32
        return 'console';
33
    }
34
}
35