Skip to content

Commit f2c2891

Browse files
committed
Code: add types
1 parent c17b7b5 commit f2c2891

8 files changed

+25
-24
lines changed

src/AbstractMenuItemsContainer.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,11 @@ private function hasVisibleItemsOn(string $type): bool
138138
*/
139139
private function getVisibleItemsOn(string $type): array
140140
{
141-
return array_filter($this->getItems(), function (IMenuItem $item) use ($type): bool {
142-
return match ($type) {
141+
return array_filter($this->getItems(), fn (IMenuItem $item): bool => match ($type) {
143142
'menu' => $item->isVisibleOnMenu(),
144143
'breadcrumbs' => $item->isVisibleOnBreadcrumbs(),
145144
'sitemap' => $item->isVisibleOnSitemap(),
146145
default => false,
147-
};
148146
});
149147
}
150148

src/Config/MenuItemAction.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ final class MenuItemAction
77

88
public string $target;
99

10-
/** @var array<string, string> */
10+
/** @var array<string, mixed> */
1111
public array $parameters = [];
1212

1313
/**
14-
* @param array<string, mixed> $array
14+
* @param array{target: string, parameters?: array<string, mixed>} $array
1515
*/
1616
public static function fromArray(array $array): self
1717
{

src/Config/TemplatePaths.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
<?php
2-
3-
declare(strict_types=1);
1+
<?php declare(strict_types = 1);
42

53
namespace Contributte\MenuControl\Config;
64

src/DI/MenuExtension.php

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -136,15 +136,20 @@ private function loadMenuConfiguration(
136136
*/
137137
private function normalizeMenuItems(Processor $processor, array $items): array
138138
{
139-
array_walk($items, function (array &$item, string $key) use ($processor): void {
140-
$item = $processor->process($this->getItemSchema(), $item);
141-
142-
if ($item->title === null) {
143-
$item->title = $key;
139+
array_walk(
140+
$items,
141+
// @phpcs:ignore SlevomatCodingStandard.PHP.DisallowReference.DisallowedPassingByReference
142+
function (&$item, string $key) use ($processor): void {
143+
$item = $processor->process($this->getItemSchema(), $item);
144+
assert($item instanceof stdClass);
145+
146+
if ($item->title === null) {
147+
$item->title = $key;
148+
}
149+
150+
$item->items = $this->normalizeMenuItems($processor, $item->items);
144151
}
145-
146-
$item->items = $this->normalizeMenuItems($processor, $item->items);
147-
});
152+
);
148153

149154
return $items;
150155
}

src/IMenuItem.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public function isAllowed(): bool;
1515
public function getActionTarget(): ?string;
1616

1717
/**
18-
* @return array<string, string>
18+
* @return array<string, mixed>
1919
*/
2020
public function getActionParameters(): array;
2121

src/Loaders/DefaultMenuLoader.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use Contributte\MenuControl\IMenu;
77
use Contributte\MenuControl\IMenuItem;
88
use Contributte\MenuControl\IMenuItemsContainer;
9-
use Nette\Utils;
9+
use Nette\Utils\Validators;
1010
use stdClass;
1111

1212
final class DefaultMenuLoader implements IMenuLoader
@@ -49,7 +49,7 @@ private function processItem(IMenuItemsContainer $parent, string $name, stdClass
4949

5050
if ($config->action !== null) {
5151
if (is_array($config->action)) {
52-
$item->setAction(MenuItemAction::fromArray($config->action));
52+
$item->setAction(MenuItemAction::fromArray($config->action)); // @phpstan-ignore-line
5353
} else {
5454
$item->setAction(MenuItemAction::fromString($config->action));
5555
}
@@ -61,7 +61,7 @@ private function processItem(IMenuItemsContainer $parent, string $name, stdClass
6161

6262
if ($config->include !== null) {
6363
$include = array_map(function ($include) {
64-
Utils\Validators::assert($include, 'string');
64+
Validators::assert($include, 'string');
6565

6666
return $include;
6767
}, is_array($config->include) ? $config->include : [$config->include]);

src/MenuItem.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public function getActionTarget(): ?string
9191
}
9292

9393
/**
94-
* @return array<string, string>
94+
* @return array<string, mixed>
9595
*/
9696
public function getActionParameters(): array
9797
{

src/Traits/MenuItemData.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@
55
trait MenuItemData
66
{
77

8-
/** @var array<string, string> */
8+
/** @var array<string, mixed> */
99
private array $data = [];
1010

1111
/**
12-
* @return array<string, string>
12+
* @return array<string, mixed>
1313
*/
1414
public function getData(): array
1515
{
1616
return $this->data;
1717
}
1818

1919
/**
20-
* @param array<string, string> $data
20+
* @param array<string, mixed> $data
2121
*/
2222
public function setData(array $data): void
2323
{

0 commit comments

Comments
 (0)