Skip to content

Commit 23cbf9d

Browse files
committed
added type hints (BC break)
1 parent d24c147 commit 23cbf9d

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
@@ -134,10 +134,9 @@ public function getHtmlName(): string
134134

135135
/**
136136
* Sets control's value.
137-
* @return static
138137
* @internal
139138
*/
140-
public function setValue(mixed $value)
139+
public function setValue($value): static
141140
{
142141
$this->value = $value;
143142
return $this;
@@ -148,7 +147,7 @@ public function setValue(mixed $value)
148147
* Returns control's value.
149148
* @return mixed
150149
*/
151-
public function getValue()
150+
public function getValue(): mixed
152151
{
153152
return $this->value;
154153
}
@@ -166,9 +165,8 @@ public function isFilled(): bool
166165

167166
/**
168167
* Sets control's default value.
169-
* @return static
170168
*/
171-
public function setDefaultValue($value)
169+
public function setDefaultValue($value): static
172170
{
173171
$form = $this->getForm(throw: false);
174172
if ($this->isDisabled() || !$form || !$form->isAnchored() || !$form->isSubmitted()) {
@@ -181,9 +179,8 @@ public function setDefaultValue($value)
181179

182180
/**
183181
* Disables or enables control.
184-
* @return static
185182
*/
186-
public function setDisabled(bool $state = true)
183+
public function setDisabled(bool $state = true): static
187184
{
188185
$this->disabled = $state;
189186
if ($state) {
@@ -229,9 +226,8 @@ public function isOmitted(): bool
229226

230227
/**
231228
* Generates control's HTML element.
232-
* @return Html|string
233229
*/
234-
public function getControl()
230+
public function getControl(): Html|string
235231
{
236232
$this->setOption('rendered', true);
237233
$el = clone $this->control;
@@ -247,9 +243,8 @@ public function getControl()
247243

248244
/**
249245
* Generates label's HTML element.
250-
* @return Html|string|null
251246
*/
252-
public function getLabel(string|Stringable|null $caption = null)
247+
public function getLabel(string|Stringable|null $caption = null): Html|string|null
253248
{
254249
$label = clone $this->label;
255250
$label->for = $this->getHtmlId();
@@ -397,13 +392,13 @@ public function translate($value, ...$parameters): mixed
397392

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

src/Forms/Controls/Checkbox.php

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

3535
/**
3636
* Sets control's value.
37-
* @return static
3837
* @internal
3938
*/
40-
public function setValue($value)
39+
public function setValue($value): static
4140
{
4241
if (!is_scalar($value) && $value !== null) {
4342
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
@@ -44,10 +44,9 @@ public function loadHttpData(): void
4444
/**
4545
* Sets selected item (by key).
4646
* @param string|int|\BackedEnum|null $value
47-
* @return static
4847
* @internal
4948
*/
50-
public function setValue($value)
49+
public function setValue($value): static
5150
{
5251
if ($value instanceof \BackedEnum) {
5352
$value = $value->value;
@@ -97,9 +96,8 @@ public function isFilled(): bool
9796

9897
/**
9998
* Sets items from which to choose.
100-
* @return static
10199
*/
102-
public function setItems(array $items, bool $useKeys = true)
100+
public function setItems(array $items, bool $useKeys = true): static
103101
{
104102
$this->items = $useKeys ? $items : array_combine($items, $items);
105103
return $this;

src/Forms/Controls/HiddenField.php

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

4141
/**
4242
* Sets control's value.
43-
* @return static
4443
* @internal
4544
*/
46-
public function setValue($value)
45+
public function setValue($value): static
4746
{
4847
if ($value === null) {
4948
$value = '';

src/Forms/Controls/MultiChoiceControl.php

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

4343
/**
4444
* Sets selected items (by keys).
45-
* @return static
4645
* @internal
4746
*/
48-
public function setValue($values)
47+
public function setValue($values): static
4948
{
5049
if (is_scalar($values) || $values === null) {
5150
$values = (array) $values;
@@ -96,9 +95,8 @@ public function getRawValue(): array
9695

9796
/**
9897
* Sets items from which to choose.
99-
* @return static
10098
*/
101-
public function setItems(array $items, bool $useKeys = true)
99+
public function setItems(array $items, bool $useKeys = true): static
102100
{
103101
$this->items = $useKeys ? $items : array_combine($items, $items);
104102
return $this;

src/Forms/Controls/MultiSelectBox.php

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

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

src/Forms/Controls/SelectBox.php

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

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

src/Forms/Controls/TextBase.php

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

2929
/**
3030
* Sets control's value.
31-
* @return static
3231
* @internal
3332
*/
34-
public function setValue($value)
33+
public function setValue($value): static
3534
{
3635
if ($value === null) {
3736
$value = '';
@@ -126,12 +125,12 @@ protected function getRenderedValue(): ?string
126125
}
127126

128127

129-
/** @return static */
130128
public function addRule(
131129
callable|string $validator,
132130
string|Stringable|null $errorMessage = null,
133131
mixed $arg = null,
134-
) {
132+
): static
133+
{
135134
foreach ($this->getRules() as $rule) {
136135
if (!$rule->canExport() && !$rule->branch) {
137136
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
@@ -62,12 +62,12 @@ public function getControl(): Nette\Utils\Html
6262
}
6363

6464

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

0 commit comments

Comments
 (0)