Skip to content

Commit 3fc5d40

Browse files
committed
Add missing type hints and adjust PHPDoc annotations
1 parent 2fed4cc commit 3fc5d40

File tree

10 files changed

+119
-38
lines changed

10 files changed

+119
-38
lines changed

Attribute/Crud.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
final public const FETCH_MANUAL = 'manual';
1111

1212
/**
13-
* @var string auto|manual
13+
* @var 'auto'|'manual'|null
1414
* Check if fields should be fetched automatically or manually
1515
*/
1616
public ?string $fetchMode;

Attribute/Field.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
readonly class Field
77
{
88

9+
/**
10+
* @param array<string, mixed> $options
11+
*/
912
public function __construct(
1013
public ?string $label = null,
1114
public ?string $twigName = null,
@@ -20,4 +23,4 @@ public function __construct(
2023
public mixed $payload = null
2124
) {}
2225

23-
}
26+
}

Controller/Crud.php

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,10 @@ abstract class Crud extends AbstractController
6464
/** @var EntityRepository<T> */
6565
protected EntityRepository $repository;
6666

67+
/** @var Fields<T> */
6768
protected Fields $fields;
6869

70+
/** @var Filters<T> */
6971
protected Filters $filters;
7072

7173
/** If the Crud is active and fully loaded */
@@ -332,7 +334,7 @@ public function toggleBooleanPostAction(Request $request, $entity): Response
332334
if (!$this->isEditableBoolean($entity)) {
333335
throw $this->createAccessDeniedException("Entity {$this->getEntity()} cannot be edited (boolean).");
334336
}
335-
337+
336338
$index = $request->request->get('index');
337339
$value = $request->request->getBoolean('checked');
338340
$propertyAccessor = PropertyAccess::createPropertyAccessor();
@@ -661,6 +663,7 @@ protected function createNew(): object
661663

662664
/**
663665
* Overrides a form type. By default, forms are created using a custom formBuilder.
666+
* @param T $entity
664667
*/
665668
protected function overrideFormType($entity, bool $creation): ?string
666669
{
@@ -770,6 +773,8 @@ protected function getFieldFetchMode(): string
770773

771774
/**
772775
* Fields that will be used to display the list of entities.
776+
*
777+
* @return Fields<T>
773778
*/
774779
protected function getListingFields(): Fields
775780
{
@@ -778,6 +783,8 @@ protected function getListingFields(): Fields
778783

779784
/**
780785
* Fields that will be used to display the detail of an entity.
786+
*
787+
* @return Fields<T>
781788
*/
782789
protected function getViewFields(): Fields
783790
{
@@ -786,6 +793,8 @@ protected function getViewFields(): Fields
786793

787794
/**
788795
* Fields that will be used for the export of an entity.
796+
*
797+
* @return Fields<T>
789798
*/
790799
protected function getExportFields(): Fields
791800
{
@@ -794,12 +803,17 @@ protected function getExportFields(): Fields
794803

795804
/**
796805
* Fields that will be used to automatically generate the form in the create / edit actions.
806+
*
807+
* @return Fields<T>
797808
*/
798809
protected function getFormFields(): Fields
799810
{
800811
return clone $this->fields->filter(static fn(Field $field) => $field->isDisplayedInForm());
801812
}
802813

814+
/**
815+
* @return Filters<T>
816+
*/
803817
protected function getFilters(): Filters
804818
{
805819
return $this->filters;
@@ -823,6 +837,8 @@ public function load(Request $request): void
823837

824838
/**
825839
* Creates a Fields object without any field by default
840+
*
841+
* @return Fields<T>
826842
*/
827843
protected function createFields(): Fields
828844
{
@@ -831,6 +847,8 @@ protected function createFields(): Fields
831847

832848
/**
833849
* Creates a Fields object with default fields
850+
*
851+
* @return Fields<T>
834852
*/
835853
protected function createFieldsFromMetadata(): Fields
836854
{
@@ -869,6 +887,9 @@ protected function createFieldsFromMetadata(): Fields
869887
return $fields;
870888
}
871889

890+
/**
891+
* @return Filters<T>
892+
*/
872893
final protected function createFilters(): Filters
873894
{
874895
return new Filters($this->metadata, $this->fieldService);
@@ -967,6 +988,7 @@ protected function createFilterForm(): FormBuilderInterface
967988
/**
968989
* All the actions that will generate Routes.
969990
* Every functions that end with "Actions" will be considered as an Action and thus, a new route will be automatically created.
991+
* @return array<string>
970992
*/
971993
public function getAllActions(): array
972994
{
@@ -983,7 +1005,7 @@ public function getAllActions(): array
9831005

9841006
/**
9851007
* Finds the entity from an id.
986-
* @return T
1008+
* @return T|null
9871009
*/
9881010
public function guessEntity()
9891011
{
@@ -1003,11 +1025,12 @@ public function getDescription(): string
10031025
}
10041026

10051027
/**
1006-
* The default paginations options. Used to add a default sorting on the listing page.
1028+
* The default pagination options. Used to add a default sorting on the listing page.
1029+
* @param Fields<T> $fields
1030+
* @return array<string, string>
10071031
*/
10081032
protected function getPaginationOptions(Fields $fields): array
10091033
{
1010-
/** @var Fields|Field[] $fields */
10111034
foreach ($fields as $field) {
10121035
if ($field->getDefaultSortDirection() !== null) {
10131036
return ['defaultSortFieldName' => 'e.' . $field->getIndex(), 'defaultSortDirection' => $field->getDefaultSortDirection()];
@@ -1028,7 +1051,7 @@ protected function getPaginationOptions(Fields $fields): array
10281051
/**
10291052
* True by default
10301053
* If true, the responsive mode will be simplified, there won't be a table but a simple list that will display entity's toString().
1031-
* This removes batch actions and fields informations.
1054+
* This removes batch actions and fields information.
10321055
* Return false to use a responsive table with more data instead.
10331056
*/
10341057
protected function simpleResponsiveMode(): bool
@@ -1063,6 +1086,9 @@ protected function backUrl(): string
10631086
return $this->generateUrl('qag.' . $this->getRoute(), $this->getListRouteParams());
10641087
}
10651088

1089+
/**
1090+
* @return array<string, mixed>
1091+
*/
10661092
protected function getListRouteParams(): array
10671093
{
10681094
$params = array_merge($this->request->query->all(), $this->request->get('referer', []));
@@ -1072,6 +1098,7 @@ protected function getListRouteParams(): array
10721098

10731099
/**
10741100
* Checks if there are actions to display in the page, so the last column can be removed if there are not.
1101+
* @param array<int, Actions<int|string>> $actionEntities
10751102
*/
10761103
protected function hasActions(array $actionEntities): bool
10771104
{
@@ -1096,6 +1123,7 @@ protected function hasQuickListQueryBuilderSecurity(): bool
10961123

10971124
/**
10981125
* Used to check if the entity is a part of the getListQueryBuilder
1126+
* @param T $entity
10991127
*/
11001128
protected function entityIsInList($entity): bool
11011129
{
@@ -1108,6 +1136,8 @@ protected function entityIsInList($entity): bool
11081136

11091137
/**
11101138
* Allows params overriding before twig rendering
1139+
* @param array<string, mixed> $params
1140+
* @return array<string, mixed>
11111141
*/
11121142
protected function retrieveParams(string $action, array $params): array
11131143
{
@@ -1118,6 +1148,9 @@ protected function retrieveParams(string $action, array $params): array
11181148
], $params);
11191149
}
11201150

1151+
/**
1152+
* @return array{0: bool, 1: string|null, 2: \Symfony\Component\Form\FormInterface|null, 3: int}
1153+
*/
11211154
protected function applySearchAndFiltersQueryBuilder(Request $request, QueryBuilder $queryBuilder): array
11221155
{
11231156
$isSearchable = $this->isSearchable();

Model/Action.php

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,14 @@ public function setLabel(?string $label): self
4646
return $this;
4747
}
4848

49+
/**
50+
* @return string[]
51+
*/
4952
public function getClasses(): array
5053
{
5154
return $this->classes;
5255
}
5356

54-
/**
55-
* @param string[] $classes
56-
*/
5757
public function addSharedClasses(string ...$classes): self
5858
{
5959
foreach ($classes as $class) {
@@ -64,9 +64,6 @@ public function addSharedClasses(string ...$classes): self
6464
return $this;
6565
}
6666

67-
/**
68-
* @param string[] $classes
69-
*/
7067
public function addClasses(string ...$classes): self
7168
{
7269
$this->classes = array_merge($this->classes, $classes);
@@ -93,16 +90,25 @@ public function removeClass(string $class): self
9390
}
9491

9592

93+
/**
94+
* @return string[]
95+
*/
9696
public function getDropdownClasses(): array
9797
{
9898
return $this->dropdownClasses;
9999
}
100100

101-
public function getAttributes(): ?array
101+
/**
102+
* @return string[]
103+
*/
104+
public function getAttributes(): array
102105
{
103106
return $this->attributes;
104107
}
105108

109+
/**
110+
* @param string[] $attributes
111+
*/
106112
public function setAttributes(array $attributes): self
107113
{
108114
$this->attributes = $attributes;
@@ -120,6 +126,9 @@ public function addAttribute(string $key, string $content): self
120126
return $this;
121127
}
122128

129+
/**
130+
* @param string[] $attributes
131+
*/
123132
public function addAttributes(array $attributes): self
124133
{
125134
$this->attributes = array_merge($this->attributes, $attributes);
@@ -131,9 +140,6 @@ public function setModal(Modal $modal): void
131140
$this->attributes = array_merge($this->attributes, $modal->toAttributes());
132141
}
133142

134-
/**
135-
* @param string[] $classes
136-
*/
137143
public function addDropDownClasses(string ...$classes): self
138144
{
139145
$this->dropdownClasses = array_merge($this->dropdownClasses, $classes);
@@ -183,4 +189,4 @@ public function setIcon(?string $icon): self
183189
return $this;
184190
}
185191

186-
}
192+
}

Model/Actions.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
use function Symfony\Component\String\u;
77

88
/**
9+
* @template TKey of array-key
10+
* @template-extends TypedArray<TKey, Action>
911
* @method Action get(string $field)
1012
*/
1113
class Actions extends TypedArray

Model/Field.php

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@
1111
class Field implements Listable
1212
{
1313

14-
/**
15-
* @var string
16-
*/
17-
protected $index;
14+
protected string $index;
1815

1916
/**
2017
* @var string
@@ -82,7 +79,7 @@ class Field implements Listable
8279
protected $formType;
8380

8481
/**
85-
* @var array
82+
* @var array<string, mixed>
8683
*/
8784
protected $options = [];
8885

@@ -264,11 +261,17 @@ public function setFormType(?string $formType): self
264261
return $this;
265262
}
266263

264+
/**
265+
* @return array<string, mixed>
266+
*/
267267
public function getOptions(): array
268268
{
269269
return $this->options;
270270
}
271271

272+
/**
273+
* @param array<string, mixed> $options
274+
*/
272275
public function setOptions(array $options): self
273276
{
274277
$this->options = $options;
@@ -332,16 +335,25 @@ public function setPosition(?int $position): void
332335
$this->position = $position;
333336
}
334337

335-
public function getPayload()
338+
/**
339+
* @return mixed
340+
*/
341+
public function getPayload(): mixed
336342
{
337343
return $this->payload;
338344
}
339345

340-
public function setPayload($payload): void
346+
/**
347+
* @param mixed $payload
348+
*/
349+
public function setPayload(mixed $payload): void
341350
{
342351
$this->payload = $payload;
343352
}
344353

354+
/**
355+
* @return array<string, mixed>
356+
*/
345357
public function guessFormOptions(): array
346358
{
347359
$options = ['label' => $this->getLabel(), 'required' => $this->isRequired()];
@@ -394,11 +406,11 @@ public function guessFormType(): ?string
394406
return match ($this->getType()) {
395407
'decimal' => TextType::class,
396408
'enum' => EnumType::class,
397-
'date' => $this->getFormType() ?? DateType::class,
398-
'datetime_immutable', 'datetime' => $this->getFormType() ?? DateTimeType::class,
399-
'relation_to_many', 'relation' => $this->getFormType() ?? EntityType::class,
409+
'date' => DateType::class,
410+
'datetime_immutable', 'datetime' => DateTimeType::class,
411+
'relation_to_many', 'relation' => EntityType::class,
400412
default => null,
401413
};
402414
}
403415

404-
}
416+
}

0 commit comments

Comments
 (0)