Passed
Push — master ( f7707e...61da39 )
by Vasyl
01:34
created

url_alias_current()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 2
nc 2
nop 1
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
if (!function_exists('route_alias')) {
4
    /**
5
     *
6
     * Get URL-path (alias/system path) for entity.
7
     * 
8
     * @param string $systemName
9
     * @param array $parameters [\Illuminate\Database\Eloquent\Model]
10
     * @param bool $absolute
11
     * @return string
12
     */
13
    function route_alias(string $systemName, $parameters = [], $absolute = true): string
14
    {
15
        $parameters = array_wrap($parameters);
16
17
        if (! empty($parameters[0]) && ($parameters[0] instanceof \Illuminate\Database\Eloquent\Model)) {
18
            $entity = $parameters[0];
19
            if ($alias = optional($entity->urlAlias)->aliased_path) {
20
                unset($parameters[0]);
21
                if (count($parameters)) {
22
                    $alias = $alias . '?' . http_build_query($parameters);
23
                }
24
                return $absolute ? url($alias) : $alias;
0 ignored issues
show
Bug introduced by
The function url was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

24
                return $absolute ? /** @scrutinizer ignore-call */ url($alias) : $alias;
Loading history...
25
            }
26
        }
27
28
        return route($systemName, $parameters, $absolute);
0 ignored issues
show
Bug introduced by
The function route was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

28
        return /** @scrutinizer ignore-call */ route($systemName, $parameters, $absolute);
Loading history...
29
    }
30
}
31
32
33
if (!function_exists('url_alias_current')) {
34
    /**
35
     * Get current url alias path or system path.
36
     *
37
     * @param string $str
38
     * @return array
39
     */
40
    function url_alias_current($absolute = true): string
41
    {
42
        $path = request()->server('ALIAS_REQUEST_URI', request()->path());
0 ignored issues
show
Bug introduced by
The function request was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

42
        $path = /** @scrutinizer ignore-call */ request()->server('ALIAS_REQUEST_URI', request()->path());
Loading history...
43
        
44
        return $absolute ? url($path) : $path;
0 ignored issues
show
Bug introduced by
The function url was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

44
        return $absolute ? /** @scrutinizer ignore-call */ url($path) : $path;
Loading history...
45
    }
46
}
47
48