Skip to content

Commit 42ea967

Browse files
committed
added type hints (BC break)
1 parent 16c747f commit 42ea967

File tree

12 files changed

+27
-45
lines changed

12 files changed

+27
-45
lines changed

src/Forms/Control.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,14 @@ interface Control
1818
/**
1919
* Sets control's value.
2020
* @param mixed $value
21-
* @return static
2221
*/
23-
function setValue(mixed $value);
22+
function setValue(mixed $value): static;
2423

2524
/**
2625
* Returns control's value.
2726
* @return mixed
2827
*/
29-
function getValue();
28+
function getValue(): mixed;
3029

3130
function validate(): void;
3231

src/Forms/Controls/BaseControl.php

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,9 @@ public function getHtmlName(): string
133133

134134
/**
135135
* Sets control's value.
136-
* @return static
137136
* @internal
138137
*/
139-
public function setValue(mixed $value)
138+
public function setValue($value): static
140139
{
141140
$this->value = $value;
142141
return $this;
@@ -147,7 +146,7 @@ public function setValue(mixed $value)
147146
* Returns control's value.
148147
* @return mixed
149148
*/
150-
public function getValue()
149+
public function getValue(): mixed
151150
{
152151
return $this->value;
153152
}
@@ -165,9 +164,8 @@ public function isFilled(): bool
165164

166165
/**
167166
* Sets control's default value.
168-
* @return static
169167
*/
170-
public function setDefaultValue($value)
168+
public function setDefaultValue($value): static
171169
{
172170
$form = $this->getForm(throw: false);
173171
if ($this->isDisabled() || !$form || !$form->isAnchored() || !$form->isSubmitted()) {
@@ -180,9 +178,8 @@ public function setDefaultValue($value)
180178

181179
/**
182180
* Disables or enables control.
183-
* @return static
184181
*/
185-
public function setDisabled(bool $state = true)
182+
public function setDisabled(bool $state = true): static
186183
{
187184
$this->disabled = $state;
188185
if ($state) {
@@ -228,9 +225,8 @@ public function isOmitted(): bool
228225

229226
/**
230227
* Generates control's HTML element.
231-
* @return Html|string
232228
*/
233-
public function getControl()
229+
public function getControl(): Html|string
234230
{
235231
$this->setOption('rendered', true);
236232
$el = clone $this->control;
@@ -246,9 +242,8 @@ public function getControl()
246242

247243
/**
248244
* Generates label's HTML element.
249-
* @return Html|string|null
250245
*/
251-
public function getLabel(string|Stringable|null $caption = null)
246+
public function getLabel(string|Stringable|null $caption = null): Html|string|null
252247
{
253248
$label = clone $this->label;
254249
$label->for = $this->getHtmlId();
@@ -396,13 +391,13 @@ public function translate($value, ...$parameters): mixed
396391

397392
/**
398393
* Adds a validation rule.
399-
* @return static
400394
*/
401395
public function addRule(
402396
callable|string $validator,
403397
string|Stringable|null $errorMessage = null,
404398
mixed $arg = null,
405-
) {
399+
): static
400+
{
406401
$this->rules->addRule($validator, $errorMessage, $arg);
407402
return $this;
408403
}

src/Forms/Controls/Checkbox.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,9 @@ public function __construct(string|Stringable|null $label = null)
3333

3434
/**
3535
* Sets control's value.
36-
* @return static
3736
* @internal
3837
*/
39-
public function setValue($value)
38+
public function setValue($value): static
4039
{
4140
if (!is_scalar($value) && $value !== null) {
4241
throw new Nette\InvalidArgumentException(sprintf("Value must be scalar or null, %s given in field '%s'.", get_debug_type($value), $this->getName()));

src/Forms/Controls/ChoiceControl.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,9 @@ public function loadHttpData(): void
4747
/**
4848
* Sets selected item (by key).
4949
* @param string|int|\BackedEnum|null $value
50-
* @return static
5150
* @internal
5251
*/
53-
public function setValue($value)
52+
public function setValue($value): static
5453
{
5554
if ($value instanceof \BackedEnum) {
5655
$value = $value->value;
@@ -102,9 +101,8 @@ public function isFilled(): bool
102101

103102
/**
104103
* Sets items from which to choose.
105-
* @return static
106104
*/
107-
public function setItems(array $items, bool $useKeys = true)
105+
public function setItems(array $items, bool $useKeys = true): static
108106
{
109107
$this->items = $useKeys ? $items : array_combine($items, $items);
110108
return $this;

src/Forms/Controls/HiddenField.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,9 @@ public function __construct($persistentValue = null)
3939

4040
/**
4141
* Sets control's value.
42-
* @return static
4342
* @internal
4443
*/
45-
public function setValue($value)
44+
public function setValue($value): static
4645
{
4746
if ($value === null) {
4847
$value = '';

src/Forms/Controls/MultiChoiceControl.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,9 @@ public function loadHttpData(): void
4444

4545
/**
4646
* Sets selected items (by keys).
47-
* @return static
4847
* @internal
4948
*/
50-
public function setValue($values)
49+
public function setValue($values): static
5150
{
5251
if (is_scalar($values) || $values === null) {
5352
$values = (array) $values;
@@ -111,9 +110,8 @@ public function isFilled(): bool
111110

112111
/**
113112
* Sets items from which to choose.
114-
* @return static
115113
*/
116-
public function setItems(array $items, bool $useKeys = true)
114+
public function setItems(array $items, bool $useKeys = true): static
117115
{
118116
$this->items = $useKeys ? $items : array_combine($items, $items);
119117
return $this;

src/Forms/Controls/MultiSelectBox.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,8 @@ public function __construct($label = null, ?array $items = null)
3131

3232
/**
3333
* Sets options and option groups from which to choose.
34-
* @return static
3534
*/
36-
public function setItems(array $items, bool $useKeys = true)
35+
public function setItems(array $items, bool $useKeys = true): static
3736
{
3837
if (!$useKeys) {
3938
$res = [];

src/Forms/Controls/SelectBox.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,8 @@ public function getPrompt(): string|Stringable|false
6363

6464
/**
6565
* Sets options and option groups from which to choose.
66-
* @return static
6766
*/
68-
public function setItems(array $items, bool $useKeys = true)
67+
public function setItems(array $items, bool $useKeys = true): static
6968
{
7069
if (!$useKeys) {
7170
$res = [];

src/Forms/Controls/TextBase.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,9 @@ abstract class TextBase extends BaseControl
2727

2828
/**
2929
* Sets control's value.
30-
* @return static
3130
* @internal
3231
*/
33-
public function setValue($value)
32+
public function setValue($value): static
3433
{
3534
if ($value === null) {
3635
$value = '';
@@ -125,12 +124,12 @@ protected function getRenderedValue(): ?string
125124
}
126125

127126

128-
/** @return static */
129127
public function addRule(
130128
callable|string $validator,
131129
string|Stringable|null $errorMessage = null,
132130
mixed $arg = null,
133-
) {
131+
): static
132+
{
134133
foreach ($this->getRules() as $rule) {
135134
if (!$rule->canExport() && !$rule->branch) {
136135
return parent::addRule($validator, $errorMessage, $arg);

src/Forms/Controls/TextInput.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,12 @@ public function getControl(): Nette\Utils\Html
6161
}
6262

6363

64-
/** @return static */
6564
public function addRule(
6665
callable|string $validator,
6766
string|Stringable|null $errorMessage = null,
6867
mixed $arg = null,
69-
) {
68+
): static
69+
{
7070
foreach ($this->getRules() as $rule) {
7171
if (!$rule->canExport() && !$rule->branch) {
7272
return parent::addRule($validator, $errorMessage, $arg);

0 commit comments

Comments
 (0)