1 | <?php |
||||
2 | |||||
3 | namespace LeKoala\Admini; |
||||
4 | |||||
5 | use SilverStripe\Core\Convert; |
||||
6 | use SilverStripe\Core\Injector\Injectable; |
||||
7 | use SilverStripe\ORM\FieldType\DBField; |
||||
8 | use SilverStripe\ORM\FieldType\DBHTMLText; |
||||
9 | |||||
10 | /** |
||||
11 | * A simple CMS menu item. |
||||
12 | * |
||||
13 | * Items can be added to the menu through custom {@link LeftAndMainExtension} |
||||
14 | * classes and {@link CMSMenu}. |
||||
15 | * |
||||
16 | * @see CMSMenu |
||||
17 | */ |
||||
18 | class CMSMenuItem |
||||
19 | { |
||||
20 | use Injectable; |
||||
21 | |||||
22 | /** |
||||
23 | * The (translated) menu title |
||||
24 | * @var string $title |
||||
25 | */ |
||||
26 | public $title; |
||||
27 | |||||
28 | /** |
||||
29 | * Relative URL |
||||
30 | * @var string $url |
||||
31 | */ |
||||
32 | public $url; |
||||
33 | |||||
34 | /** |
||||
35 | * Parent controller class name |
||||
36 | * @var string $controller |
||||
37 | */ |
||||
38 | public $controller; |
||||
39 | |||||
40 | /** |
||||
41 | * Menu priority (sort order) |
||||
42 | * @var integer $priority |
||||
43 | */ |
||||
44 | public $priority; |
||||
45 | |||||
46 | /** |
||||
47 | * Attributes for the link. For instance, custom data attributes or standard |
||||
48 | * HTML anchor properties. |
||||
49 | * |
||||
50 | * @var string |
||||
51 | */ |
||||
52 | protected $attributes = []; |
||||
53 | |||||
54 | /** |
||||
55 | * @var string |
||||
56 | */ |
||||
57 | public $iconName; |
||||
58 | |||||
59 | /** |
||||
60 | * Create a new CMS Menu Item |
||||
61 | * |
||||
62 | * @param string $title |
||||
63 | * @param string $url |
||||
64 | * @param string $controller Controller class name |
||||
65 | * @param integer $priority The sort priority of the item |
||||
66 | * @param string $iconName |
||||
67 | */ |
||||
68 | public function __construct($title, $url, $controller = null, $priority = -1, $iconName = null) |
||||
69 | { |
||||
70 | $this->title = $title; |
||||
71 | $this->url = $url; |
||||
72 | $this->controller = $controller; |
||||
73 | $this->priority = $priority; |
||||
74 | $this->iconName = $iconName; |
||||
75 | } |
||||
76 | |||||
77 | /** |
||||
78 | * @param array $attributes |
||||
79 | */ |
||||
80 | public function setAttributes($attributes) |
||||
81 | { |
||||
82 | $this->attributes = $attributes; |
||||
0 ignored issues
–
show
|
|||||
83 | } |
||||
84 | |||||
85 | /** |
||||
86 | * @param string $extraClass |
||||
87 | */ |
||||
88 | public function addExtraClass($extraClass) |
||||
89 | { |
||||
90 | $class = $this->attributes["class"] ?? ""; |
||||
91 | $class .= " " . $extraClass; |
||||
92 | $this->attributes["class"] = $class; |
||||
93 | } |
||||
94 | |||||
95 | /** |
||||
96 | * @param array $attrs |
||||
97 | * @return DBHTMLText |
||||
98 | */ |
||||
99 | public function getAttributesHTML($attrs = null) |
||||
100 | { |
||||
101 | $excludeKeys = (is_string($attrs)) ? func_get_args() : null; |
||||
102 | |||||
103 | if (!$attrs || is_string($attrs)) { |
||||
104 | $attrs = $this->attributes; |
||||
105 | } |
||||
106 | |||||
107 | // Remove empty or excluded values |
||||
108 | foreach ($attrs as $key => $value) { |
||||
109 | if (($excludeKeys && in_array($key, $excludeKeys)) |
||||
110 | || (!$value && $value !== 0 && $value !== '0') |
||||
111 | ) { |
||||
112 | unset($attrs[$key]); |
||||
113 | continue; |
||||
114 | } |
||||
115 | } |
||||
116 | |||||
117 | // Create markkup |
||||
118 | $parts = array(); |
||||
119 | |||||
120 | foreach ($attrs as $name => $value) { |
||||
121 | if ($value === true) { |
||||
122 | $value = $name; |
||||
123 | } |
||||
124 | |||||
125 | $parts[] = sprintf('%s="%s"', Convert::raw2att($name), Convert::raw2att($value)); |
||||
0 ignored issues
–
show
It seems like
SilverStripe\Core\Convert::raw2att($name) can also be of type array and array ; however, parameter $values of sprintf() does only seem to accept double|integer|string , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
126 | } |
||||
127 | |||||
128 | /** @var DBHTMLText $fragment */ |
||||
129 | $fragment = DBField::create_field('HTMLFragment', implode(' ', $parts)); |
||||
130 | return $fragment; |
||||
131 | } |
||||
132 | } |
||||
133 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..