Skip to content

Commit 6ab5aa3

Browse files
committed
improved phpDoc
1 parent c76a0b9 commit 6ab5aa3

28 files changed

Lines changed: 175 additions & 33 deletions

src/Bridges/FormsLatte/Nodes/FieldNNameNode.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,10 @@ private function init(Tag $tag): void
9898
}
9999

100100

101-
/** @internal */
101+
/**
102+
* @internal
103+
* @return string[]
104+
*/
102105
public static function findUsedAttributes(ElementNode $el): array
103106
{
104107
$res = [];

src/Bridges/FormsLatte/Nodes/FormContainerNode.php

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

2828

29-
/** @return \Generator<int, ?array, array{AreaNode, ?Tag}, static|AreaNode> */
29+
/** @return \Generator<int, ?array<mixed>, array{AreaNode, ?Tag}, static|AreaNode> */
3030
public static function create(Tag $tag): \Generator
3131
{
3232
$tag->outputMode = $tag::OutputRemoveIndentation;

src/Bridges/FormsLatte/Nodes/FormNode.php

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

3636

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

src/Bridges/FormsLatte/Nodes/LabelNode.php

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

3737

38-
/** @return \Generator<int, ?array, array{AreaNode, ?Tag}, static|AreaNode> */
38+
/** @return \Generator<int, ?array<mixed>, array{AreaNode, ?Tag}, static|AreaNode> */
3939
public static function create(Tag $tag): \Generator
4040
{
4141
if ($tag->isNAttribute()) {

src/Bridges/FormsLatte/Runtime.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public static function initializeForm(Form $form): void
3535

3636
/**
3737
* Renders form begin.
38+
* @param array<string, mixed> $attrs
3839
*/
3940
public static function renderFormBegin(Form $form, array $attrs, bool $withTags = true): string
4041
{
@@ -77,6 +78,7 @@ public static function renderFormEnd(Form $form, bool $withTags = true): string
7778
}
7879

7980

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

src/Forms/Container.php

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@
1818
/**
1919
* Container for form controls.
2020
*
21-
* @property ArrayHash $values
21+
* @property ArrayHash<mixed> $values
2222
* @property-read \Iterator $controls
23-
* @property-read Form|null $form
23+
* @property-read ?Form $form
24+
* @implements \ArrayAccess<string|int, Nette\ComponentModel\IComponent>
2425
*/
2526
class Container extends Nette\ComponentModel\Container implements \ArrayAccess
2627
{
@@ -30,12 +31,12 @@ class Container extends Nette\ComponentModel\Container implements \ArrayAccess
3031

3132
/**
3233
* Occurs when the form was validated
33-
* @var array<callable(self, array|object): void|callable(array|object): void>
34+
* @var array<callable(self, mixed[]|object): void | callable(mixed[]|object): void>
3435
*/
3536
public array $onValidate = [];
3637
protected ?ControlGroup $currentGroup = null;
3738

38-
/** @var callable[] extension methods */
39+
/** @var array<string, callable(self): mixed> */
3940
private static array $extMethods = [];
4041
private ?bool $validated = false;
4142
private ?string $mappedType = null;
@@ -46,6 +47,7 @@ class Container extends Nette\ComponentModel\Container implements \ArrayAccess
4647

4748
/**
4849
* Fill-in with default values.
50+
* @param mixed[]|object $data
4951
*/
5052
public function setDefaults(array|object $data, bool $erase = false): static
5153
{
@@ -57,6 +59,7 @@ public function setDefaults(array|object $data, bool $erase = false): static
5759

5860
/**
5961
* Fill-in with values.
62+
* @param mixed[]|object $values
6063
* @internal
6164
*/
6265
public function setValues(array|object $values, bool $erase = false, bool $onlyDisabled = false): static
@@ -83,7 +86,10 @@ public function setValues(array|object $values, bool $erase = false, bool $onlyD
8386

8487
/**
8588
* Returns the values submitted by the form.
86-
* @param Control[]|null $controls
89+
* @template T of object
90+
* @param class-string<T>|T|'array'|true|null $returnType
91+
* @param ?list<Control> $controls
92+
* @return ($returnType is class-string<T>|T ? T : ($returnType is 'array'|true ? mixed[] : ArrayHash<mixed>))
8793
*/
8894
public function getValues(string|object|bool|null $returnType = null, ?array $controls = null): object|array
8995
{
@@ -121,7 +127,10 @@ public function getValues(string|object|bool|null $returnType = null, ?array $co
121127

122128
/**
123129
* Returns the potentially unvalidated values submitted by the form.
124-
* @param Control[]|null $controls
130+
* @template T of object
131+
* @param class-string<T>|T|'array'|null $returnType
132+
* @param ?list<Control> $controls
133+
* @return ($returnType is class-string<T>|T ? T : ($returnType is 'array' ? mixed[] : ArrayHash<mixed>))
125134
*/
126135
public function getUntrustedValues(string|object|null $returnType = null, ?array $controls = null): object|array
127136
{
@@ -179,6 +188,7 @@ public function getUnsafeValues($returnType, ?array $controls = null)
179188
}
180189

181190

191+
/** @param class-string $type */
182192
public function setMappedType(string $type): static
183193
{
184194
$this->mappedType = $type;
@@ -237,6 +247,7 @@ public function validate(?array $controls = null): void
237247

238248
/**
239249
* Returns all validation errors.
250+
* @return string[]
240251
*/
241252
public function getErrors(): array
242253
{
@@ -286,6 +297,7 @@ public function addComponent(
286297

287298
/**
288299
* Iterates over all form controls.
300+
* @return iterable<Control>
289301
*/
290302
public function getControls(): \Iterator
291303
{
@@ -464,6 +476,7 @@ public function addCheckbox(string $name, string|Stringable|null $caption = null
464476

465477
/**
466478
* Adds set of radio button controls to the form.
479+
* @param ?mixed[] $items
467480
*/
468481
public function addRadioList(
469482
string $name,
@@ -477,6 +490,7 @@ public function addRadioList(
477490

478491
/**
479492
* Adds set of checkbox controls to the form.
493+
* @param ?mixed[] $items
480494
*/
481495
public function addCheckboxList(
482496
string $name,
@@ -490,6 +504,7 @@ public function addCheckboxList(
490504

491505
/**
492506
* Adds select box control that allows single item selection.
507+
* @param ?mixed[] $items
493508
*/
494509
public function addSelect(
495510
string $name,
@@ -505,6 +520,7 @@ public function addSelect(
505520

506521
/**
507522
* Adds select box control that allows multiple item selection.
523+
* @param ?mixed[] $items
508524
*/
509525
public function addMultiSelect(
510526
string $name,
@@ -578,6 +594,7 @@ public function addContainer(string|int $name): self
578594
/********************* extension methods ****************d*g**/
579595

580596

597+
/** @param mixed[] $args */
581598
public function __call(string $name, array $args)
582599
{
583600
if (isset(self::$extMethods[$name])) {

src/Forms/Control.php

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

3333
/**
3434
* Returns errors corresponding to control.
35+
* @return string[]
3536
*/
3637
function getErrors(): array;
3738

src/Forms/ControlGroup.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@
1818
*/
1919
class ControlGroup
2020
{
21+
/** @var \WeakMap<Control, null> */
2122
protected \WeakMap $controls;
23+
24+
/** @var array<string, mixed> */
2225
private array $options = [];
2326

2427

@@ -28,6 +31,7 @@ public function __construct()
2831
}
2932

3033

34+
/** @param Control|Container|iterable<Control|Container> ...$items */
3135
public function add(...$items): static
3236
{
3337
foreach ($items as $item) {
@@ -115,6 +119,7 @@ public function getOption(string $key): mixed
115119

116120
/**
117121
* Returns user-specific options.
122+
* @return array<string, mixed>
118123
*/
119124
public function getOptions(): array
120125
{

src/Forms/Controls/BaseControl.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434
* @property-read Html $labelPrototype
3535
* @property bool $required
3636
* @property-read bool $filled
37-
* @property-read array $errors
38-
* @property-read array $options
37+
* @property-read string[] $errors
38+
* @property-read array<string,mixed> $options
3939
* @property-read string $error
4040
*/
4141
abstract class BaseControl extends Nette\ComponentModel\Component implements Control
@@ -49,15 +49,19 @@ abstract class BaseControl extends Nette\ComponentModel\Component implements Con
4949
/** @var bool|bool[] */
5050
protected bool|array $disabled = false;
5151

52-
/** @var callable[][] extension methods */
52+
/** @var array<string, array<class-string, callable(self): mixed>> */
5353
private static array $extMethods = [];
5454
private string|Stringable|null $caption;
55+
56+
/** @var string[] */
5557
private array $errors = [];
5658
private ?bool $omitted = null;
5759
private Rules $rules;
5860

5961
/** true means autodetect */
6062
private Nette\Localization\Translator|bool|null $translator = true;
63+
64+
/** @var array<string, mixed> */
6165
private array $options = [];
6266

6367

@@ -397,6 +401,7 @@ public function translate($value, ...$parameters): mixed
397401

398402
/**
399403
* Adds a validation rule.
404+
* @param (callable(self): bool)|string $validator
400405
* @return static
401406
*/
402407
public function addRule(
@@ -411,6 +416,7 @@ public function addRule(
411416

412417
/**
413418
* Adds a validation condition a returns new branch.
419+
* @param (callable(self): bool)|string|bool $validator
414420
*/
415421
public function addCondition($validator, $value = null): Rules
416422
{
@@ -420,6 +426,7 @@ public function addCondition($validator, $value = null): Rules
420426

421427
/**
422428
* Adds a validation condition based on another control a returns new branch.
429+
* @param (callable(self): bool)|string $validator
423430
*/
424431
public function addConditionOn(Control $control, $validator, $value = null): Rules
425432
{
@@ -429,6 +436,7 @@ public function addConditionOn(Control $control, $validator, $value = null): Rul
429436

430437
/**
431438
* Adds an input filter callback.
439+
* @param callable(mixed): mixed $filter
432440
*/
433441
public function addFilter(callable $filter): static
434442
{
@@ -496,6 +504,7 @@ public function getError(): ?string
496504

497505
/**
498506
* Returns errors corresponding to control.
507+
* @return string[]
499508
*/
500509
public function getErrors(): array
501510
{
@@ -548,6 +557,7 @@ public function getOption($key): mixed
548557

549558
/**
550559
* Returns user-specific options.
560+
* @return array<string, mixed>
551561
*/
552562
public function getOptions(): array
553563
{
@@ -558,6 +568,7 @@ public function getOptions(): array
558568
/********************* extension methods ****************d*g**/
559569

560570

571+
/** @param mixed[] $args */
561572
public function __call(string $name, array $args)
562573
{
563574
$class = static::class;

src/Forms/Controls/CheckboxList.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class CheckboxList extends MultiChoiceControl
2929
protected Html $itemLabel;
3030

3131

32+
/** @param ?mixed[] $items */
3233
public function __construct(string|Stringable|null $label = null, ?array $items = null)
3334
{
3435
parent::__construct($label, $items);

0 commit comments

Comments
 (0)