MenuItem   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 8
dl 0
loc 61
rs 10
c 2
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A section() 0 8 1
A system() 0 8 1
A linkToUrl() 0 14 2
A linkToRoute() 0 8 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Braunstetter\MenuBundle\Factory;
6
7
use Braunstetter\MenuBundle\Items\RouteMenuItem;
8
use Braunstetter\MenuBundle\Items\SectionMenuItem;
9
use Braunstetter\MenuBundle\Items\SystemMenuItem;
10
use Braunstetter\MenuBundle\Items\UrlMenuItem;
11
12
final class MenuItem
13
{
14
    /**
15
     * @param array<string, string> $routeParameters
16
     * @param array<string, mixed> $options
17
     */
18
    public static function linkToRoute(
19
        string $label,
20
        string $routeName,
21
        array $routeParameters = [],
22
        ?string $icon = null,
23
        ?array $options = []
24
    ): RouteMenuItem {
25
        return new RouteMenuItem($label, $routeName, $routeParameters, $icon, $options);
26
    }
27
28
    /**
29
     * @param array<string, mixed> $options
30
     */
31
    public static function linkToUrl(
32
        string $label,
33
        string $url,
34
        ?string $target = null,
35
        ?string $icon = null,
36
        ?array $options = []
37
    ): UrlMenuItem {
38
        if ($target) {
39
            $options = array_replace($options ?? [], [
40
                'target' => $target,
41
            ]);
42
        }
43
44
        return new UrlMenuItem($label, $url, $icon, $options);
45
    }
46
47
    /**
48
     * @param array<string, string> $routeParameters
49
     * @param array<string, mixed> $options
50
     */
51
    public static function section(
52
        string $label,
53
        string|null $routeName = null,
54
        array $routeParameters = [],
55
        ?string $icon = null,
56
        ?array $options = []
57
    ): SectionMenuItem {
58
        return new SectionMenuItem($label, $routeName, $routeParameters, $icon, $options);
59
    }
60
61
    /**
62
     * @param array<string, string> $routeParameters
63
     * @param array<string, mixed> $options
64
     */
65
    public static function system(
66
        string $label,
67
        string|null $routeName = null,
68
        array $routeParameters = [],
69
        ?string $icon = null,
70
        ?array $options = []
71
    ): SystemMenuItem {
72
        return new SystemMenuItem($label, $routeName, $routeParameters, $icon, $options);
73
    }
74
}
75