Skip to content

Commit f3e4bb4

Browse files
committed
Fixed PHPStan
1 parent a547799 commit f3e4bb4

File tree

4 files changed

+18
-5
lines changed

4 files changed

+18
-5
lines changed

src/lib/Twig/Components/Checkbox/ListField.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,14 @@ final class ListField extends AbstractField
2626
{
2727
use ListFieldTrait;
2828

29+
/** @var array<string|int> */
2930
public array $value = [];
3031

32+
/**
33+
* @param CheckboxItem $item
34+
*
35+
* @return CheckboxItem
36+
*/
3137
protected function modifyListItem(array $item): array
3238
{
3339
$item['checked'] = in_array($item['value'], $this->value, true);

src/lib/Twig/Components/InputText/Field.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ final class Field extends AbstractField
2929

3030
public string $type = 'input-text';
3131

32+
public string $value = '';
33+
3234
/**
3335
* @return AttrMap
3436
*/
@@ -63,5 +65,7 @@ protected function configurePropsResolver(OptionsResolver $resolver): void
6365
});
6466
$resolver->setRequired(['name']);
6567
$resolver->setAllowedTypes('id', ['null', 'string']);
68+
$resolver->setDefaults(['value' => '']);
69+
$resolver->setAllowedTypes('value', 'string');
6670
}
6771
}

src/lib/Twig/Components/ListFieldTrait.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,17 @@
1616
* value: string|int,
1717
* label: string,
1818
* }
19+
* @phpstan-type ListItems list<ListItem>
1920
*/
2021
trait ListFieldTrait
2122
{
2223
public string $direction = 'vertical';
2324

24-
/** @var ListItem[] */
25+
/** @var ListItems */
2526
#[ExposeInTemplate(name: 'items', getter: 'getItems')]
2627
public array $items = [];
2728

28-
/** @return ListItem[] */
29+
/** @return ListItems */
2930
public function getItems(): array
3031
{
3132
return array_map(function ($item) {
@@ -35,6 +36,11 @@ public function getItems(): array
3536
}, $this->items);
3637
}
3738

39+
/**
40+
* @param ListItem $item
41+
*
42+
* @return ListItem
43+
*/
3844
protected function modifyListItem(array $item): array
3945
{
4046
return $item;

tests/integration/Twig/Components/InputText/FieldTest.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ public function testMount(): void
2727
[
2828
'name' => 'title',
2929
'id' => 'title',
30-
'value' => 'Hello',
3130
'required' => true,
3231
'labelExtra' => ['class' => 'u-mb-1'],
3332
'helperTextExtra' => ['data-test' => 'help'],
@@ -39,7 +38,6 @@ public function testMount(): void
3938

4039
self::assertSame('title', $component->name, 'Prop "name" should be set on the component.');
4140
self::assertSame('title', $component->id, 'Prop "id" should be set on the component.');
42-
self::assertSame('Hello', $component->value, 'Prop "value" should be set on the component.');
4341
self::assertTrue($component->required, 'Prop "required" should be true.');
4442

4543
/** @var array<string, mixed> $label */
@@ -53,7 +51,6 @@ public function testMount(): void
5351
self::assertSame('title', $input['id'] ?? null, 'Input "id" should be set from prop.');
5452
self::assertSame('title', $input['name'] ?? null, 'Input "name" should be set from prop.');
5553
self::assertTrue((bool)($input['required'] ?? false), 'Input should have required attribute.');
56-
self::assertSame('Hello', $input['value'] ?? null, 'Input "value" should pass through.');
5754
self::assertSame('true', $input['data-ids-custom-init'] ?? null, 'Input should include data-ids-custom-init="true".');
5855
self::assertSame('ids-input u-w-full', $input['class'] ?? null, 'Input class should be merged.');
5956
self::assertSame('Type…', $input['placeholder'] ?? null, 'Input placeholder should be merged.');

0 commit comments

Comments
 (0)