Skip to content

Commit 48aa123

Browse files
committed
added missing native types
1 parent b74ad02 commit 48aa123

11 files changed

Lines changed: 39 additions & 40 deletions

File tree

src/Bridges/FormsLatte/Runtime.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public static function renderFormEnd(Form $form, bool $withTags = true): string
7777

7878

7979
/** @param object{formsStack: Form[]} $global */
80-
public static function item($item, $global): object
80+
public static function item(object|string|int $item, object $global): object
8181
{
8282
if (is_object($item)) {
8383
return $item;

src/Forms/Container.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ public function addFloat(string $name, string|Stringable|null $label = null): Co
403403
/**
404404
* Adds input for date selection.
405405
*/
406-
public function addDate(string $name, string|object|null $label = null): Controls\DateTimeControl
406+
public function addDate(string $name, string|Stringable|null $label = null): Controls\DateTimeControl
407407
{
408408
return $this[$name] = new Controls\DateTimeControl($label, Controls\DateTimeControl::TypeDate);
409409
}
@@ -414,7 +414,7 @@ public function addDate(string $name, string|object|null $label = null): Control
414414
*/
415415
public function addTime(
416416
string $name,
417-
string|object|null $label = null,
417+
string|Stringable|null $label = null,
418418
bool $withSeconds = false,
419419
): Controls\DateTimeControl
420420
{
@@ -427,7 +427,7 @@ public function addTime(
427427
*/
428428
public function addDateTime(
429429
string $name,
430-
string|object|null $label = null,
430+
string|Stringable|null $label = null,
431431
bool $withSeconds = false,
432432
): Controls\DateTimeControl
433433
{
@@ -456,7 +456,7 @@ public function addMultiUpload(string $name, string|Stringable|null $label = nul
456456
/**
457457
* Adds hidden form control used to store a non-displayed value.
458458
*/
459-
public function addHidden(string $name, $default = null): Controls\HiddenField
459+
public function addHidden(string $name, mixed $default = null): Controls\HiddenField
460460
{
461461
return $this[$name] = (new Controls\HiddenField)
462462
->setDefaultValue($default);
@@ -593,7 +593,7 @@ public function addContainer(string|int $name): self
593593

594594

595595
/** @param mixed[] $args */
596-
public function __call(string $name, array $args)
596+
public function __call(string $name, array $args): mixed
597597
{
598598
if (isset(self::$extMethods[$name])) {
599599
return (self::$extMethods[$name])($this, ...$args);
@@ -604,7 +604,7 @@ public function __call(string $name, array $args)
604604

605605

606606
/** @param callable(self): mixed $callback */
607-
public static function extensionMethod(string $name, /*callable*/ $callback): void
607+
public static function extensionMethod(string $name, callable $callback): void
608608
{
609609
if (str_contains($name, '::')) { // back compatibility
610610
[, $name] = explode('::', $name);

src/Forms/ControlGroup.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function __construct()
3030

3131

3232
/** @param Control|Container|iterable<Control|Container> ...$items */
33-
public function add(...$items): static
33+
public function add(Control|Container|iterable ...$items): static
3434
{
3535
foreach ($items as $item) {
3636
if ($item instanceof Control) {
@@ -40,12 +40,8 @@ public function add(...$items): static
4040
foreach ($item->getComponents() as $component) {
4141
$this->add($component);
4242
}
43-
} elseif (is_iterable($item)) {
44-
$this->add(...$item);
45-
4643
} else {
47-
$type = get_debug_type($item);
48-
throw new Nette\InvalidArgumentException("Control or Container items expected, $type given.");
44+
$this->add(...$item);
4945
}
5046
}
5147

src/Forms/Controls/BaseControl.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ abstract class BaseControl extends Nette\ComponentModel\Component implements Con
5757
private Rules $rules;
5858

5959
/** true means autodetect */
60-
private Nette\Localization\Translator|bool|null $translator = true;
60+
private Nette\Localization\Translator|true|null $translator = true;
6161

6262
/** @var array<string, mixed> */
6363
private array $options = [];
@@ -170,7 +170,7 @@ public function isFilled(): bool
170170
* Sets control's default value.
171171
* @return static
172172
*/
173-
public function setDefaultValue($value)
173+
public function setDefaultValue(mixed $value)
174174
{
175175
$form = $this->getForm(throw: false);
176176
if ($this->isDisabled() || !$form || !$form->isAnchored() || !$form->isSubmitted()) {
@@ -379,7 +379,7 @@ public function getTranslator(): ?Nette\Localization\Translator
379379
/**
380380
* Returns translated string.
381381
*/
382-
public function translate($value, ...$parameters): mixed
382+
public function translate(mixed $value, mixed ...$parameters): mixed
383383
{
384384
if ($translator = $this->getTranslator()) {
385385
$tmp = is_array($value) ? [&$value] : [[&$value]];
@@ -416,7 +416,7 @@ public function addRule(
416416
* Adds a validation condition a returns new branch.
417417
* @param (callable(Control): bool)|string|bool $validator
418418
*/
419-
public function addCondition($validator, $value = null): Rules
419+
public function addCondition($validator, mixed $value = null): Rules
420420
{
421421
return $this->rules->addCondition($validator, $value);
422422
}
@@ -426,7 +426,7 @@ public function addCondition($validator, $value = null): Rules
426426
* Adds a validation condition based on another control a returns new branch.
427427
* @param (callable(Control): bool)|string $validator
428428
*/
429-
public function addConditionOn(Control $control, $validator, $value = null): Rules
429+
public function addConditionOn(Control $control, $validator, mixed $value = null): Rules
430430
{
431431
return $this->rules->addConditionOn($control, $validator, $value);
432432
}
@@ -583,7 +583,7 @@ public function __call(string $name, array $args)
583583

584584

585585
/** @param callable(self): mixed $callback */
586-
public static function extensionMethod(string $name, /*callable*/ $callback): void
586+
public static function extensionMethod(string $name, callable $callback): void
587587
{
588588
if (str_contains($name, '::')) { // back compatibility
589589
[, $name] = explode('::', $name);

src/Forms/Controls/HiddenField.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class HiddenField extends BaseControl
2222
private bool $nullable = false;
2323

2424

25-
public function __construct($persistentValue = null)
25+
public function __construct(mixed $persistentValue = null)
2626
{
2727
parent::__construct();
2828
$this->control->type = 'hidden';

src/Forms/Controls/MultiSelectBox.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class MultiSelectBox extends MultiChoiceControl
2424

2525

2626
/** @param ?mixed[] $items */
27-
public function __construct($label = null, ?array $items = null)
27+
public function __construct(string|\Stringable|null $label = null, ?array $items = null)
2828
{
2929
parent::__construct($label, $items);
3030
$this->setOption('type', 'select');

src/Forms/Form.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ public function fireEvents(): void
521521

522522

523523
/** @param iterable<callable> $handlers */
524-
private function invokeHandlers(iterable $handlers, $button = null): void
524+
private function invokeHandlers(iterable $handlers, ?SubmitterControl $button = null): void
525525
{
526526
foreach ($handlers as $handler) {
527527
$params = Nette\Utils\Callback::toReflection($handler)->getParameters();
@@ -730,7 +730,7 @@ public function fireRenderEvents(): void
730730
/**
731731
* Renders form.
732732
*/
733-
public function render(...$args): void
733+
public function render(mixed ...$args): void
734734
{
735735
$this->fireRenderEvents();
736736
echo $this->getRenderer()->render($this, ...$args);

src/Forms/Helpers.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public static function extractHttpData(
6969

7070

7171
/** @return string|mixed[]|Nette\Http\FileUpload|null */
72-
private static function sanitize(int $type, $value): string|array|Nette\Http\FileUpload|null
72+
private static function sanitize(int $type, mixed $value): string|array|Nette\Http\FileUpload|null
7373
{
7474
if ($type === Form::DataText) {
7575
return is_scalar($value)
@@ -183,7 +183,7 @@ public static function createInputList(
183183
array $items,
184184
?array $inputAttrs = null,
185185
?array $labelAttrs = null,
186-
$wrapper = null,
186+
Html|string|null $wrapper = null,
187187
): string
188188
{
189189
[$inputAttrs, $inputTag] = self::prepareAttrs($inputAttrs, 'input');
@@ -219,7 +219,7 @@ public static function createInputList(
219219
* @param mixed[] $items
220220
* @param ?array<string, mixed> $optionAttrs
221221
*/
222-
public static function createSelectBox(array $items, ?array $optionAttrs = null, $selected = null): Html
222+
public static function createSelectBox(array $items, ?array $optionAttrs = null, mixed $selected = null): Html
223223
{
224224
if ($selected !== null) {
225225
$optionAttrs['selected?'] = $selected;
@@ -304,7 +304,7 @@ public static function iniGetSize(string $name): int
304304
* @internal
305305
* @return ?class-string
306306
*/
307-
public static function getSingleType($reflection): ?string
307+
public static function getSingleType(\ReflectionParameter|\ReflectionProperty $reflection): ?string
308308
{
309309
$type = Nette\Utils\Type::fromReflection($reflection);
310310
if (!$type) {
@@ -320,7 +320,10 @@ public static function getSingleType($reflection): ?string
320320

321321

322322
/** @internal */
323-
public static function tryEnumConversion(mixed $value, $reflection): mixed
323+
public static function tryEnumConversion(
324+
mixed $value,
325+
\ReflectionParameter|\ReflectionProperty|null $reflection,
326+
): mixed
324327
{
325328
if ($value !== null
326329
&& $reflection

src/Forms/Rules.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public function removeRule(callable|string $validator): static
117117
* Adds a validation condition and returns new branch.
118118
* @param (callable(Control): bool)|string|bool $validator
119119
*/
120-
public function addCondition($validator, $arg = null): static
120+
public function addCondition(callable|string|bool $validator, mixed $arg = null): static
121121
{
122122
if ($validator === Form::Valid || $validator === ~Form::Valid) {
123123
throw new Nette\InvalidArgumentException('You cannot use Form::Valid in the addCondition method.');
@@ -134,7 +134,7 @@ public function addCondition($validator, $arg = null): static
134134
* Adds a validation condition on specified control a returns new branch.
135135
* @param (callable(Control): bool)|string $validator
136136
*/
137-
public function addConditionOn(Control $control, $validator, $arg = null): static
137+
public function addConditionOn(Control $control, callable|string $validator, mixed $arg = null): static
138138
{
139139
$rule = new Rule;
140140
$rule->control = $control;
@@ -345,7 +345,7 @@ private function adjustOperation(Rule $rule): void
345345
}
346346

347347

348-
private static function getCallback(Rule $rule)
348+
private static function getCallback(Rule $rule): array|callable|string
349349
{
350350
$op = $rule->validator;
351351
return is_string($op) && str_starts_with($op, ':')

src/Forms/Validator.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public static function formatMessage(Rule $rule, bool $withValue = true): string
113113
/**
114114
* Is control's value equal with second parameter?
115115
*/
116-
public static function validateEqual(Control $control, $arg): bool
116+
public static function validateEqual(Control $control, mixed $arg): bool
117117
{
118118
$value = $control->getValue();
119119
$values = is_array($value) ? $value : [$value];
@@ -140,7 +140,7 @@ public static function validateEqual(Control $control, $arg): bool
140140
/**
141141
* Is control's value not equal with second parameter?
142142
*/
143-
public static function validateNotEqual(Control $control, $arg): bool
143+
public static function validateNotEqual(Control $control, mixed $arg): bool
144144
{
145145
return !static::validateEqual($control, $arg);
146146
}
@@ -199,7 +199,7 @@ public static function validateRange(Control $control, array $range): bool
199199
/**
200200
* Is a control's value number greater than or equal to the specified minimum?
201201
*/
202-
public static function validateMin(Control $control, $minimum): bool
202+
public static function validateMin(Control $control, int|float|string|\DateTimeInterface $minimum): bool
203203
{
204204
return Validators::isInRange($control->getValue(), [$minimum === '' ? null : $minimum, null]);
205205
}
@@ -208,7 +208,7 @@ public static function validateMin(Control $control, $minimum): bool
208208
/**
209209
* Is a control's value number less than or equal to the specified maximum?
210210
*/
211-
public static function validateMax(Control $control, $maximum): bool
211+
public static function validateMax(Control $control, int|float|string|\DateTimeInterface $maximum): bool
212212
{
213213
return Validators::isInRange($control->getValue(), [null, $maximum === '' ? null : $maximum]);
214214
}
@@ -232,7 +232,7 @@ public static function validateLength(Control $control, array|int $range): bool
232232
/**
233233
* Has control's value minimal count/length?
234234
*/
235-
public static function validateMinLength(Control $control, $length): bool
235+
public static function validateMinLength(Control $control, int $length): bool
236236
{
237237
return static::validateLength($control, [$length, null]);
238238
}
@@ -241,7 +241,7 @@ public static function validateMinLength(Control $control, $length): bool
241241
/**
242242
* Is control's value count/length in limit?
243243
*/
244-
public static function validateMaxLength(Control $control, $length): bool
244+
public static function validateMaxLength(Control $control, int $length): bool
245245
{
246246
return static::validateLength($control, [null, $length]);
247247
}
@@ -359,7 +359,7 @@ public static function validateFloat(Control $control): bool
359359
/**
360360
* Is file size in limit?
361361
*/
362-
public static function validateFileSize(Controls\UploadControl $control, $limit): bool
362+
public static function validateFileSize(Controls\UploadControl $control, int $limit): bool
363363
{
364364
foreach (static::toArray($control->getValue()) as $file) {
365365
if ($file->getSize() > $limit || $file->getError() === UPLOAD_ERR_INI_SIZE) {
@@ -405,7 +405,7 @@ public static function validateImage(Controls\UploadControl $control): bool
405405

406406

407407
/** @return mixed[] */
408-
private static function toArray($value): array
408+
private static function toArray(mixed $value): array
409409
{
410410
return is_object($value) ? [$value] : (array) $value;
411411
}

0 commit comments

Comments
 (0)