Skip to content

Commit b74ad02

Browse files
committed
improved phpDoc types
1 parent eb92ff6 commit b74ad02

29 files changed

Lines changed: 180 additions & 34 deletions

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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public static function initializeForm(Form $form): void
3333

3434
/**
3535
* Renders form begin.
36+
* @param array<string, mixed> $attrs
3637
*/
3738
public static function renderFormBegin(Form $form, array $attrs, bool $withTags = true): string
3839
{
@@ -75,6 +76,7 @@ public static function renderFormEnd(Form $form, bool $withTags = true): string
7576
}
7677

7778

79+
/** @param object{formsStack: Form[]} $global */
7880
public static function item($item, $global): object
7981
{
8082
if (is_object($item)) {

src/Forms/Container.php

Lines changed: 24 additions & 6 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, (Control|Container)&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(self, 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(self): 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
* Fill-in with default values.
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
* Fill-in 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> $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> $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
{
@@ -177,6 +186,7 @@ public function getUnsafeValues($returnType, ?array $controls = null)
177186
}
178187

179188

189+
/** @param class-string $type */
180190
public function setMappedType(string $type): static
181191
{
182192
$this->mappedType = $type;
@@ -235,6 +245,7 @@ public function validate(?array $controls = null): void
235245

236246
/**
237247
* Returns all validation errors.
248+
* @return list<string|Stringable>
238249
*/
239250
public function getErrors(): array
240251
{
@@ -284,6 +295,7 @@ public function addComponent(
284295

285296
/**
286297
* Iterates over all form controls.
298+
* @return iterable<Control>
287299
*/
288300
public function getControls(): \Iterator
289301
{
@@ -462,6 +474,7 @@ public function addCheckbox(string $name, string|Stringable|null $caption = null
462474

463475
/**
464476
* Adds set of radio button controls to the form.
477+
* @param ?mixed[] $items
465478
*/
466479
public function addRadioList(
467480
string $name,
@@ -475,6 +488,7 @@ public function addRadioList(
475488

476489
/**
477490
* Adds set of checkbox controls to the form.
491+
* @param ?mixed[] $items
478492
*/
479493
public function addCheckboxList(
480494
string $name,
@@ -488,6 +502,7 @@ public function addCheckboxList(
488502

489503
/**
490504
* Adds select box control that allows single item selection.
505+
* @param ?mixed[] $items
491506
*/
492507
public function addSelect(
493508
string $name,
@@ -503,6 +518,7 @@ public function addSelect(
503518

504519
/**
505520
* Adds select box control that allows multiple item selection.
521+
* @param ?mixed[] $items
506522
*/
507523
public function addMultiSelect(
508524
string $name,
@@ -576,6 +592,7 @@ public function addContainer(string|int $name): self
576592
/********************* extension methods ****************d*g**/
577593

578594

595+
/** @param mixed[] $args */
579596
public function __call(string $name, array $args)
580597
{
581598
if (isset(self::$extMethods[$name])) {
@@ -586,6 +603,7 @@ public function __call(string $name, array $args)
586603
}
587604

588605

606+
/** @param callable(self): mixed $callback */
589607
public static function extensionMethod(string $name, /*callable*/ $callback): void
590608
{
591609
if (str_contains($name, '::')) { // back compatibility

src/Forms/Control.php

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

3131
/**
3232
* Returns errors corresponding to control.
33+
* @return list<string|\Stringable>
3334
*/
3435
function getErrors(): array;
3536

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) {
@@ -113,6 +117,7 @@ public function getOption(string $key): mixed
113117

114118
/**
115119
* Returns user-specific options.
120+
* @return array<string, mixed>
116121
*/
117122
public function getOptions(): array
118123
{

src/Forms/Controls/BaseControl.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
* @property-read Html $labelPrototype
3333
* @property bool $required
3434
* @property-read bool $filled
35-
* @property-read array $errors
36-
* @property-read array $options
35+
* @property-read string[] $errors
36+
* @property-read array<string,mixed> $options
3737
* @property-read string $error
3838
*/
3939
abstract class BaseControl extends Nette\ComponentModel\Component implements Control
@@ -47,15 +47,19 @@ abstract class BaseControl extends Nette\ComponentModel\Component implements Con
4747
/** @var bool|bool[] */
4848
protected bool|array $disabled = false;
4949

50-
/** @var callable[][] extension methods */
50+
/** @var array<string, array<class-string, callable(self): mixed>> */
5151
private static array $extMethods = [];
5252
private string|Stringable|null $caption;
53+
54+
/** @var list<string|Stringable> */
5355
private array $errors = [];
5456
private ?bool $omitted = null;
5557
private Rules $rules;
5658

5759
/** true means autodetect */
5860
private Nette\Localization\Translator|bool|null $translator = true;
61+
62+
/** @var array<string, mixed> */
5963
private array $options = [];
6064

6165

@@ -395,6 +399,7 @@ public function translate($value, ...$parameters): mixed
395399

396400
/**
397401
* Adds a validation rule.
402+
* @param (callable(Control): bool)|string $validator
398403
* @return static
399404
*/
400405
public function addRule(
@@ -409,6 +414,7 @@ public function addRule(
409414

410415
/**
411416
* Adds a validation condition a returns new branch.
417+
* @param (callable(Control): bool)|string|bool $validator
412418
*/
413419
public function addCondition($validator, $value = null): Rules
414420
{
@@ -418,6 +424,7 @@ public function addCondition($validator, $value = null): Rules
418424

419425
/**
420426
* Adds a validation condition based on another control a returns new branch.
427+
* @param (callable(Control): bool)|string $validator
421428
*/
422429
public function addConditionOn(Control $control, $validator, $value = null): Rules
423430
{
@@ -427,6 +434,7 @@ public function addConditionOn(Control $control, $validator, $value = null): Rul
427434

428435
/**
429436
* Adds an input filter callback.
437+
* @param callable(mixed): mixed $filter
430438
*/
431439
public function addFilter(callable $filter): static
432440
{
@@ -494,6 +502,7 @@ public function getError(): ?string
494502

495503
/**
496504
* Returns errors corresponding to control.
505+
* @return list<string|Stringable>
497506
*/
498507
public function getErrors(): array
499508
{
@@ -546,6 +555,7 @@ public function getOption($key): mixed
546555

547556
/**
548557
* Returns user-specific options.
558+
* @return array<string, mixed>
549559
*/
550560
public function getOptions(): array
551561
{
@@ -556,6 +566,7 @@ public function getOptions(): array
556566
/********************* extension methods ****************d*g**/
557567

558568

569+
/** @param mixed[] $args */
559570
public function __call(string $name, array $args)
560571
{
561572
$class = static::class;
@@ -571,6 +582,7 @@ public function __call(string $name, array $args)
571582
}
572583

573584

585+
/** @param callable(self): mixed $callback */
574586
public static function extensionMethod(string $name, /*callable*/ $callback): void
575587
{
576588
if (str_contains($name, '::')) { // back compatibility

0 commit comments

Comments
 (0)