Skip to content

Commit 67ca440

Browse files
committed
Refactor Input and AbstractDropdown classes for improved type safety and code clarity
1 parent 977d64e commit 67ca440

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

src/lib/Twig/Components/AbstractDropdown.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,22 @@
1717
use Symfony\UX\TwigComponent\Attribute\PreMount;
1818

1919
/**
20-
* @phpstan-type DropdownItem array{
20+
* @phpstan-type TDropdownItem array{
2121
* id: string,
2222
* label: string
2323
* }
2424
*/
2525
abstract class AbstractDropdown
2626
{
27-
private const TRANSLATION_DOMAIN = 'ibexa_design_system_twig';
27+
private const string TRANSLATION_DOMAIN = 'ibexa_design_system_twig';
2828

2929
public string $name;
3030

3131
public bool $disabled = false;
3232

3333
public bool $error = false;
3434

35-
/** @var array<DropdownItem> */
35+
/** @var array<TDropdownItem> */
3636
public array $items = [];
3737

3838
public string $placeholder;
@@ -100,7 +100,7 @@ abstract protected function configurePropsResolver(OptionsResolver $resolver): v
100100
* @param Options<array<string, mixed>> $options
101101
* @param array<int, mixed> $items
102102
*
103-
* @return array<int, DropdownItem>
103+
* @return array<int, TDropdownItem>
104104
*/
105105
private static function normalizeItems(Options $options, array $items): array
106106
{
@@ -112,7 +112,7 @@ private static function normalizeItems(Options $options, array $items): array
112112
->setAllowedTypes('label', 'string');
113113

114114
foreach ($items as $index => $item) {
115-
if (!\is_array($item)) {
115+
if (!is_array($item)) {
116116
throw new InvalidOptionsException(
117117
sprintf(
118118
'Each dropdown item must be an array, "%s" given at index %d.',
@@ -122,9 +122,7 @@ private static function normalizeItems(Options $options, array $items): array
122122
);
123123
}
124124

125-
$resolvedItem = $itemResolver->resolve($item);
126-
127-
$items[$index] = $resolvedItem;
125+
$items[$index] = $itemResolver->resolve($item);
128126
}
129127

130128
return $items;

src/lib/Twig/Components/DropdownSingle/Input.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function postMount(): void
3131
public function getSelectedLabel(): string
3232
{
3333
$value = $this->value ?? '';
34-
$selected_item = array_find($this->items, static function (array $item) use ($value) {
34+
$selected_item = array_find($this->items, static function (array $item) use ($value): bool {
3535
return $item['id'] === $value;
3636
});
3737

0 commit comments

Comments
 (0)