Skip to content

Commit 8831e01

Browse files
committed
phpdoc generics for Control
1 parent b5bd901 commit 8831e01

11 files changed

+18
-5
lines changed

src/Forms/Control.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,19 @@
1212

1313
/**
1414
* Defines method that must be implemented to allow a component to act like a form control.
15+
* @template T
1516
*/
1617
interface Control
1718
{
1819
/**
1920
* Sets control's value.
20-
* @param mixed $value
21+
* @param T|null $value
2122
*/
2223
function setValue(mixed $value): static;
2324

2425
/**
2526
* Returns control's value.
26-
* @return mixed
27+
* @return T|null
2728
*/
2829
function getValue(): mixed;
2930

src/Forms/Controls/BaseControl.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636
* @property-read array $errors
3737
* @property-read array $options
3838
* @property-read string $error
39+
*
40+
* @template T
41+
* @implements Control<T>
3942
*/
4043
abstract class BaseControl extends Nette\ComponentModel\Component implements Control
4144
{
@@ -152,7 +155,6 @@ public function setValue($value): static
152155

153156
/**
154157
* Returns control's value.
155-
* @return mixed
156158
*/
157159
public function getValue(): mixed
158160
{

src/Forms/Controls/Button.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
/**
1717
* Push button control with no default behavior.
18+
* @extends BaseControl<string>
1819
*/
1920
class Button extends BaseControl
2021
{

src/Forms/Controls/Checkbox.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
/**
1818
* Check box control. Allows the user to select a true or false condition.
19+
* @extends BaseControl<bool>
1920
*/
2021
class Checkbox extends BaseControl
2122
{

src/Forms/Controls/ChoiceControl.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
*
1818
* @property array $items
1919
* @property-read mixed $selectedItem
20+
*
21+
* @extends BaseControl<array-key>
2022
*/
2123
abstract class ChoiceControl extends BaseControl
2224
{
@@ -68,7 +70,6 @@ public function setValue($value): static
6870

6971
/**
7072
* Returns selected key.
71-
* @return string|int|null
7273
*/
7374
public function getValue(): mixed
7475
{

src/Forms/Controls/CsrfProtection.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
/**
1818
* CSRF protection field.
19+
* @extends BaseControl<null>
1920
*/
2021
class CsrfProtection extends HiddenField
2122
{

src/Forms/Controls/HiddenField.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
/**
1818
* Hidden form control used to store a non-displayed value.
19+
* @extends BaseControl<string>
1920
*/
2021
class HiddenField extends BaseControl
2122
{

src/Forms/Controls/ImageButton.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
/**
1414
* Submittable image button form control.
15+
* @method array|null getValue()
1516
*/
1617
class ImageButton extends SubmitButton
1718
{

src/Forms/Controls/MultiChoiceControl.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
*
1818
* @property array $items
1919
* @property-read array $selectedItems
20+
*
21+
* @extends BaseControl<array-key[]>
2022
*/
2123
abstract class MultiChoiceControl extends BaseControl
2224
{
@@ -82,6 +84,7 @@ public function setValue($values): static
8284

8385
/**
8486
* Returns selected keys.
87+
* @return array-key[]
8588
*/
8689
public function getValue(): array
8790
{

src/Forms/Controls/TextBase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
/**
1919
* Implements the basic functionality common to text input controls.
20+
* @extends BaseControl<string>
2021
*/
2122
abstract class TextBase extends BaseControl
2223
{
@@ -48,7 +49,6 @@ public function setValue($value): static
4849

4950
/**
5051
* Returns control's value.
51-
* @return mixed
5252
*/
5353
public function getValue(): mixed
5454
{

src/Forms/Controls/UploadControl.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
/**
2020
* Text box and browse button that allow users to select a file to upload to the server.
21+
* @extends BaseControl<FileUpload|FileUpload[]>
2122
*/
2223
class UploadControl extends BaseControl
2324
{

0 commit comments

Comments
 (0)