Skip to content

Commit 01863f2

Browse files
committed
improved phpDoc types
1 parent be40d7f commit 01863f2

29 files changed

Lines changed: 178 additions & 38 deletions

src/Bridges/FormsDI/FormsExtension.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
/**
1515
* Forms extension for Nette DI.
16+
*
17+
* @property object{messages: array<string, string>} $config
1618
*/
1719
class FormsExtension extends Nette\DI\CompilerExtension
1820
{

src/Bridges/FormsLatte/Nodes/FieldNNameNode.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ final class FieldNNameNode extends StatementNode
3131
public AreaNode $content;
3232

3333

34+
/** @return \Generator<int, ?list<string>, array{AreaNode, ?Tag}, static> */
3435
public static function create(Tag $tag): \Generator
3536
{
3637
$tag->expectArguments();
@@ -96,7 +97,10 @@ private function init(Tag $tag): void
9697
}
9798

9899

99-
/** @internal */
100+
/**
101+
* @internal
102+
* @return string[]
103+
*/
100104
public static function findUsedAttributes(ElementNode $el): array
101105
{
102106
$res = [];

src/Bridges/FormsLatte/Nodes/FormContainerNode.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class FormContainerNode extends StatementNode
2424
public AreaNode $content;
2525

2626

27-
/** @return \Generator<int, ?array, array{AreaNode, ?Tag}, static|AreaNode> */
27+
/** @return \Generator<int, ?list<string>, array{AreaNode, ?Tag}, static> */
2828
public static function create(Tag $tag): \Generator
2929
{
3030
$tag->outputMode = $tag::OutputRemoveIndentation;

src/Bridges/FormsLatte/Nodes/FormNNameNode.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ final class FormNNameNode extends StatementNode
2626
public AreaNode $content;
2727

2828

29+
/** @return \Generator<int, ?list<string>, array{AreaNode, ?Tag}, static> */
2930
public static function create(Tag $tag): \Generator
3031
{
3132
$tag->expectArguments();

src/Bridges/FormsLatte/Nodes/FormNode.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class FormNode extends StatementNode
3232
public ?Position $endLine;
3333

3434

35-
/** @return \Generator<int, ?array, array{AreaNode, ?Tag}, static|AreaNode> */
35+
/** @return \Generator<int, ?list<string>, array{AreaNode, ?Tag}, static> */
3636
public static function create(Tag $tag): \Generator
3737
{
3838
if ($tag->isNAttribute()) {

src/Bridges/FormsLatte/Nodes/LabelNode.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class LabelNode extends StatementNode
3333
public ?Position $endLine;
3434

3535

36-
/** @return \Generator<int, ?array, array{AreaNode, ?Tag}, static|AreaNode> */
36+
/** @return \Generator<int, ?list<string>, array{AreaNode, ?Tag}, static> */
3737
public static function create(Tag $tag): \Generator
3838
{
3939
if ($tag->isNAttribute()) {

src/Bridges/FormsLatte/Runtime.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public static function initializeForm(Form $form): void
3636

3737
/**
3838
* Renders form begin.
39+
* @param array<string, mixed> $attrs
3940
*/
4041
public static function renderFormBegin(Form $form, array $attrs, bool $withTags = true): string
4142
{

src/Forms/Container.php

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@
1616
/**
1717
* Container for form controls.
1818
*
19-
* @property ArrayHash $values
19+
* @property ArrayHash<mixed> $values
2020
* @property-read \Iterator $controls
21-
* @property-read Form|null $form
21+
* @property-read ?Form $form
22+
* @implements \ArrayAccess<string|int, Nette\ComponentModel\IComponent>
2223
*/
2324
class Container extends Nette\ComponentModel\Container implements \ArrayAccess
2425
{
@@ -28,12 +29,12 @@ class Container extends Nette\ComponentModel\Container implements \ArrayAccess
2829

2930
/**
3031
* Occurs when the form was validated
31-
* @var array<callable(self, array|object): void|callable(array|object): void>
32+
* @var array<callable(static, mixed[]|object): void | callable(mixed[]|object): void>
3233
*/
3334
public array $onValidate = [];
3435
protected ?ControlGroup $currentGroup = null;
3536

36-
/** @var callable[] extension methods */
37+
/** @var array<string, callable(static): mixed> */
3738
private static array $extMethods = [];
3839
private ?bool $validated = false;
3940
private ?string $mappedType = null;
@@ -44,6 +45,7 @@ class Container extends Nette\ComponentModel\Container implements \ArrayAccess
4445

4546
/**
4647
* Populates controls with default values. Has no effect on submitted forms.
48+
* @param mixed[]|object $values
4749
*/
4850
public function setDefaults(array|object $values, bool $erase = false): static
4951
{
@@ -55,6 +57,7 @@ public function setDefaults(array|object $values, bool $erase = false): static
5557

5658
/**
5759
* Fills controls with values.
60+
* @param mixed[]|object $values
5861
* @internal
5962
*/
6063
public function setValues(array|object $values, bool $erase = false, bool $onlyDisabled = false): static
@@ -81,7 +84,10 @@ public function setValues(array|object $values, bool $erase = false, bool $onlyD
8184

8285
/**
8386
* Returns the values submitted by the form.
84-
* @param Control[]|null $controls
87+
* @template T of object
88+
* @param class-string<T>|T|'array'|true|null $returnType
89+
* @param ?list<Control|self> $controls
90+
* @return ($returnType is class-string<T>|T ? T : ($returnType is 'array'|true ? mixed[] : ArrayHash<mixed>))
8591
*/
8692
public function getValues(string|object|bool|null $returnType = null, ?array $controls = null): object|array
8793
{
@@ -119,7 +125,10 @@ public function getValues(string|object|bool|null $returnType = null, ?array $co
119125

120126
/**
121127
* Returns the potentially unvalidated values submitted by the form.
122-
* @param Control[]|null $controls
128+
* @template T of object
129+
* @param class-string<T>|T|'array'|null $returnType
130+
* @param ?list<Control|self> $controls
131+
* @return ($returnType is class-string<T>|T ? T : ($returnType is 'array' ? mixed[] : ArrayHash<mixed>))
123132
*/
124133
public function getUntrustedValues(string|object|null $returnType = null, ?array $controls = null): object|array
125134
{
@@ -170,7 +179,11 @@ public function getUntrustedValues(string|object|null $returnType = null, ?array
170179
}
171180

172181

173-
/** @deprecated use getUntrustedValues() */
182+
/**
183+
* @param ?list<Control|self> $controls
184+
* @return object|mixed[]
185+
* @deprecated use getUntrustedValues()
186+
*/
174187
public function getUnsafeValues($returnType, ?array $controls = null)
175188
{
176189
return $this->getUntrustedValues($returnType, $controls);
@@ -179,6 +192,7 @@ public function getUnsafeValues($returnType, ?array $controls = null)
179192

180193
/**
181194
* Sets the default class used when getValues() is called without an explicit type.
195+
* @param class-string $type
182196
*/
183197
public function setMappedType(string $type): static
184198
{
@@ -238,6 +252,7 @@ public function validate(?array $controls = null): void
238252

239253
/**
240254
* Returns all validation errors.
255+
* @return list<string|Stringable>
241256
*/
242257
public function getErrors(): array
243258
{
@@ -287,6 +302,7 @@ public function addComponent(
287302

288303
/**
289304
* Iterates over all form controls.
305+
* @return \Iterator<Control>
290306
*/
291307
public function getControls(): \Iterator
292308
{
@@ -465,6 +481,7 @@ public function addCheckbox(string $name, string|Stringable|null $caption = null
465481

466482
/**
467483
* Adds set of radio button controls to the form.
484+
* @param ?mixed[] $items
468485
*/
469486
public function addRadioList(
470487
string $name,
@@ -478,6 +495,7 @@ public function addRadioList(
478495

479496
/**
480497
* Adds set of checkbox controls to the form.
498+
* @param ?mixed[] $items
481499
*/
482500
public function addCheckboxList(
483501
string $name,
@@ -491,6 +509,7 @@ public function addCheckboxList(
491509

492510
/**
493511
* Adds select box control that allows single item selection.
512+
* @param ?mixed[] $items
494513
*/
495514
public function addSelect(
496515
string $name,
@@ -506,6 +525,7 @@ public function addSelect(
506525

507526
/**
508527
* Adds select box control that allows multiple item selection.
528+
* @param ?mixed[] $items
509529
*/
510530
public function addMultiSelect(
511531
string $name,
@@ -579,6 +599,7 @@ public function addContainer(string|int $name): self
579599
/********************* extension methods ****************d*g**/
580600

581601

602+
/** @param mixed[] $args */
582603
public function __call(string $name, array $args)
583604
{
584605
if (isset(self::$extMethods[$name])) {
@@ -589,6 +610,7 @@ public function __call(string $name, array $args)
589610
}
590611

591612

613+
/** @param callable(static): mixed $callback */
592614
public static function extensionMethod(string $name, /*callable*/ $callback): void
593615
{
594616
if (str_contains($name, '::')) { // back compatibility

src/Forms/Control.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ function validate(): void;
2626

2727
/**
2828
* Returns errors corresponding to control.
29+
* @return list<string|\Stringable>
2930
*/
3031
function getErrors(): array;
3132

src/Forms/ControlGroup.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@
1616
*/
1717
class ControlGroup
1818
{
19+
/** @var \WeakMap<Control, null> */
1920
protected \WeakMap $controls;
21+
22+
/** @var array<string, mixed> */
2023
private array $options = [];
2124

2225

@@ -26,6 +29,7 @@ public function __construct()
2629
}
2730

2831

32+
/** @param Control|Container|iterable<Control|Container> ...$items */
2933
public function add(...$items): static
3034
{
3135
foreach ($items as $item) {
@@ -118,6 +122,7 @@ public function getOption(string $key): mixed
118122

119123
/**
120124
* Returns all rendering options.
125+
* @return array<string, mixed>
121126
*/
122127
public function getOptions(): array
123128
{

0 commit comments

Comments
 (0)