Link::toRoute()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 4
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Spatie\Menu\Laravel;
4
5
use Illuminate\Support\Traits\Macroable;
6
use Spatie\Menu\Link as BaseLink;
7
8
class Link extends BaseLink
9
{
10
    use Macroable;
11
12
    /**
13
     * @param string $path
14
     * @param string $text
15
     * @param mixed $parameters
16
     * @param bool|null $secure
17
     *
18
     * @return static
19
     */
20
    public static function toUrl(string $path, string $text, $parameters = [], $secure = null)
21
    {
22
        return static::to(url($path, $parameters, $secure), $text);
0 ignored issues
show
Bug introduced by
It seems like url($path, $parameters, $secure) targeting url() can also be of type object<Illuminate\Contracts\Routing\UrlGenerator>; however, Spatie\Menu\Link::to() does only seem to accept string, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
23
    }
24
25
    /**
26
     * @param string|array $action
27
     * @param string $text
28
     * @param mixed $parameters
29
     * @param bool $absolute
30
     *
31
     * @return static
32
     */
33
    public static function toAction($action, string $text, $parameters = [], bool $absolute = true)
34
    {
35
        if (is_array($action)) {
36
            $action = implode('@', $action);
37
        }
38
39
        return static::to(action($action, $parameters, $absolute), $text);
40
    }
41
42
    /**
43
     * @param string $name
44
     * @param string $text
45
     * @param mixed $parameters
46
     * @param bool $absolute
47
     *
48
     * @return static
49
     */
50
    public static function toRoute(string $name, string $text, $parameters = [], $absolute = true)
51
    {
52
        return static::to(route($name, $parameters, $absolute), $text);
53
    }
54
}
55