Skip to content

Commit 7cbe717

Browse files
committed
added missing native types
1 parent 01863f2 commit 7cbe717

11 files changed

Lines changed: 42 additions & 43 deletions

File tree

src/Bridges/FormsLatte/Runtime.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public static function renderFormEnd(Form $form, bool $withTags = true): string
8383
* Resolves a control or container from the current form on the stack.
8484
* @param object{formsStack: Form[]} $global
8585
*/
86-
public static function item($item, $global): object
86+
public static function item(object|string|int $item, object $global): object
8787
{
8888
if (is_object($item)) {
8989
return $item;

src/Forms/Container.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ public function getUntrustedValues(string|object|null $returnType = null, ?array
184184
* @return object|mixed[]
185185
* @deprecated use getUntrustedValues()
186186
*/
187-
public function getUnsafeValues($returnType, ?array $controls = null)
187+
public function getUnsafeValues(string|object|null $returnType, ?array $controls = null): object|array
188188
{
189189
return $this->getUntrustedValues($returnType, $controls);
190190
}
@@ -410,7 +410,7 @@ public function addFloat(string $name, string|Stringable|null $label = null): Co
410410
/**
411411
* Adds input for date selection.
412412
*/
413-
public function addDate(string $name, string|object|null $label = null): Controls\DateTimeControl
413+
public function addDate(string $name, string|Stringable|null $label = null): Controls\DateTimeControl
414414
{
415415
return $this[$name] = new Controls\DateTimeControl($label, Controls\DateTimeControl::TypeDate);
416416
}
@@ -421,7 +421,7 @@ public function addDate(string $name, string|object|null $label = null): Control
421421
*/
422422
public function addTime(
423423
string $name,
424-
string|object|null $label = null,
424+
string|Stringable|null $label = null,
425425
bool $withSeconds = false,
426426
): Controls\DateTimeControl
427427
{
@@ -434,7 +434,7 @@ public function addTime(
434434
*/
435435
public function addDateTime(
436436
string $name,
437-
string|object|null $label = null,
437+
string|Stringable|null $label = null,
438438
bool $withSeconds = false,
439439
): Controls\DateTimeControl
440440
{
@@ -463,7 +463,7 @@ public function addMultiUpload(string $name, string|Stringable|null $label = nul
463463
/**
464464
* Adds hidden form control used to store a non-displayed value.
465465
*/
466-
public function addHidden(string $name, $default = null): Controls\HiddenField
466+
public function addHidden(string $name, mixed $default = null): Controls\HiddenField
467467
{
468468
return $this[$name] = (new Controls\HiddenField)
469469
->setDefaultValue($default);
@@ -600,7 +600,7 @@ public function addContainer(string|int $name): self
600600

601601

602602
/** @param mixed[] $args */
603-
public function __call(string $name, array $args)
603+
public function __call(string $name, array $args): mixed
604604
{
605605
if (isset(self::$extMethods[$name])) {
606606
return (self::$extMethods[$name])($this, ...$args);
@@ -611,7 +611,7 @@ public function __call(string $name, array $args)
611611

612612

613613
/** @param callable(static): mixed $callback */
614-
public static function extensionMethod(string $name, /*callable*/ $callback): void
614+
public static function extensionMethod(string $name, callable $callback): void
615615
{
616616
if (str_contains($name, '::')) { // back compatibility
617617
[, $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: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public function loadHttpData(): void
113113
/**
114114
* Returns submitted HTTP value for this control.
115115
*/
116-
protected function getHttpData($type, ?string $htmlTail = null): mixed
116+
protected function getHttpData(int $type, ?string $htmlTail = null): mixed
117117
{
118118
return $this->getForm()->getHttpData($type, $this->getHtmlName() . $htmlTail);
119119
}
@@ -163,7 +163,7 @@ public function isFilled(): bool
163163
* Sets the default value. Has no effect on submitted or disabled controls.
164164
* @return static
165165
*/
166-
public function setDefaultValue($value)
166+
public function setDefaultValue(mixed $value)
167167
{
168168
$form = $this->getForm(throw: false);
169169
if ($this->isDisabled() || !$form || !$form->isAnchored() || !$form->isSubmitted()) {
@@ -369,7 +369,7 @@ public function getTranslator(): ?Nette\Localization\Translator
369369
/**
370370
* Translates a string or array of strings using the configured translator, or returns the value unchanged if no translator is set or the value is HtmlStringable.
371371
*/
372-
public function translate($value, ...$parameters): mixed
372+
public function translate(mixed $value, mixed ...$parameters): mixed
373373
{
374374
if ($translator = $this->getTranslator()) {
375375
$tmp = is_array($value) ? [&$value] : [[&$value]];
@@ -406,7 +406,7 @@ public function addRule(
406406
* Adds a validation condition and returns a new branch.
407407
* @param (callable(Control): bool)|string|bool $validator
408408
*/
409-
public function addCondition($validator, $value = null): Rules
409+
public function addCondition($validator, mixed $value = null): Rules
410410
{
411411
return $this->rules->addCondition($validator, $value);
412412
}
@@ -416,7 +416,7 @@ public function addCondition($validator, $value = null): Rules
416416
* Adds a validation condition based on another control and returns a new branch.
417417
* @param (callable(Control): bool)|string $validator
418418
*/
419-
public function addConditionOn(Control $control, $validator, $value = null): Rules
419+
public function addConditionOn(Control $control, $validator, mixed $value = null): Rules
420420
{
421421
return $this->rules->addConditionOn($control, $validator, $value);
422422
}
@@ -518,7 +518,7 @@ public function cleanErrors(): void
518518
/**
519519
* Sets a rendering or user-specific option (e.g. 'description', 'class', 'id').
520520
*/
521-
public function setOption($key, mixed $value): static
521+
public function setOption(string $key, mixed $value): static
522522
{
523523
if ($value === null) {
524524
unset($this->options[$key]);
@@ -533,7 +533,7 @@ public function setOption($key, mixed $value): static
533533
/**
534534
* Returns a rendering or user-specific option value.
535535
*/
536-
public function getOption($key): mixed
536+
public function getOption(string $key): mixed
537537
{
538538
if (func_num_args() > 1) {
539539
trigger_error(__METHOD__ . '() parameter $default is deprecated, use operator ??', E_USER_DEPRECATED);
@@ -573,7 +573,7 @@ public function __call(string $name, array $args)
573573

574574

575575
/** @param callable(static): mixed $callback */
576-
public static function extensionMethod(string $name, /*callable*/ $callback): void
576+
public static function extensionMethod(string $name, callable $callback): void
577577
{
578578
if (str_contains($name, '::')) { // back compatibility
579579
[, $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
@@ -499,7 +499,7 @@ public function fireEvents(): void
499499

500500

501501
/** @param iterable<callable> $handlers */
502-
private function invokeHandlers(iterable $handlers, $button = null): void
502+
private function invokeHandlers(iterable $handlers, ?SubmitterControl $button = null): void
503503
{
504504
foreach ($handlers as $handler) {
505505
$params = Nette\Utils\Callback::toReflection($handler)->getParameters();
@@ -699,7 +699,7 @@ public function fireRenderEvents(): void
699699
}
700700

701701

702-
public function render(...$args): void
702+
public function render(mixed ...$args): void
703703
{
704704
$this->fireRenderEvents();
705705
echo $this->getRenderer()->render($this, ...$args);

src/Forms/Helpers.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public static function extractHttpData(
6767
}
6868

6969

70-
private static function sanitize(int $type, $value): string|Nette\Http\FileUpload|null
70+
private static function sanitize(int $type, mixed $value): string|Nette\Http\FileUpload|null
7171
{
7272
if ($type === Form::DataText) {
7373
return is_scalar($value)
@@ -185,7 +185,7 @@ public static function createInputList(
185185
array $items,
186186
?array $inputAttrs = null,
187187
?array $labelAttrs = null,
188-
$wrapper = null,
188+
Html|string|null $wrapper = null,
189189
): string
190190
{
191191
[$inputAttrs, $inputTag] = self::prepareAttrs($inputAttrs, 'input');
@@ -222,7 +222,7 @@ public static function createInputList(
222222
* @param mixed[] $items
223223
* @param ?array<string, mixed> $optionAttrs
224224
*/
225-
public static function createSelectBox(array $items, ?array $optionAttrs = null, $selected = null): Html
225+
public static function createSelectBox(array $items, ?array $optionAttrs = null, mixed $selected = null): Html
226226
{
227227
if ($selected !== null) {
228228
$optionAttrs['selected?'] = $selected;
@@ -307,7 +307,7 @@ public static function iniGetSize(string $name): int
307307
* Returns the single type name from reflection, or null if no type is defined.
308308
* @internal
309309
*/
310-
public static function getSingleType($reflection): ?string
310+
public static function getSingleType(\ReflectionParameter|\ReflectionProperty $reflection): ?string
311311
{
312312
$type = Nette\Utils\Type::fromReflection($reflection);
313313
if (!$type) {
@@ -323,7 +323,10 @@ public static function getSingleType($reflection): ?string
323323

324324

325325
/** @internal */
326-
public static function tryEnumConversion(mixed $value, $reflection): mixed
326+
public static function tryEnumConversion(
327+
mixed $value,
328+
\ReflectionParameter|\ReflectionProperty|null $reflection,
329+
): mixed
327330
{
328331
if ($value !== null
329332
&& $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 a specified control and 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;
@@ -348,7 +348,7 @@ private function adjustOperation(Rule $rule): void
348348
}
349349

350350

351-
private static function getCallback(Rule $rule)
351+
private static function getCallback(Rule $rule): array|callable|string
352352
{
353353
$op = $rule->validator;
354354
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
@@ -112,7 +112,7 @@ public static function formatMessage(Rule $rule, bool $withValue = true): string
112112
/**
113113
* Checks whether the control's value equals the argument (string comparison, supports arrays).
114114
*/
115-
public static function validateEqual(Control $control, $arg): bool
115+
public static function validateEqual(Control $control, mixed $arg): bool
116116
{
117117
$value = $control->getValue();
118118
$values = is_array($value) ? $value : [$value];
@@ -139,7 +139,7 @@ public static function validateEqual(Control $control, $arg): bool
139139
/**
140140
* Checks whether the control's value does not equal the argument.
141141
*/
142-
public static function validateNotEqual(Control $control, $arg): bool
142+
public static function validateNotEqual(Control $control, mixed $arg): bool
143143
{
144144
return !static::validateEqual($control, $arg);
145145
}
@@ -198,7 +198,7 @@ public static function validateRange(Control $control, array $range): bool
198198
/**
199199
* Checks whether the control's value is greater than or equal to the minimum.
200200
*/
201-
public static function validateMin(Control $control, $minimum): bool
201+
public static function validateMin(Control $control, int|float|string|\DateTimeInterface $minimum): bool
202202
{
203203
return Validators::isInRange($control->getValue(), [$minimum === '' ? null : $minimum, null]);
204204
}
@@ -207,7 +207,7 @@ public static function validateMin(Control $control, $minimum): bool
207207
/**
208208
* Checks whether the control's value is less than or equal to the maximum.
209209
*/
210-
public static function validateMax(Control $control, $maximum): bool
210+
public static function validateMax(Control $control, int|float|string|\DateTimeInterface $maximum): bool
211211
{
212212
return Validators::isInRange($control->getValue(), [null, $maximum === '' ? null : $maximum]);
213213
}
@@ -231,7 +231,7 @@ public static function validateLength(Control $control, array|int $range): bool
231231
/**
232232
* Checks whether the string length or array count is at least the specified minimum.
233233
*/
234-
public static function validateMinLength(Control $control, $length): bool
234+
public static function validateMinLength(Control $control, int $length): bool
235235
{
236236
return static::validateLength($control, [$length, null]);
237237
}
@@ -240,7 +240,7 @@ public static function validateMinLength(Control $control, $length): bool
240240
/**
241241
* Checks whether the string length or array count does not exceed the specified maximum.
242242
*/
243-
public static function validateMaxLength(Control $control, $length): bool
243+
public static function validateMaxLength(Control $control, int $length): bool
244244
{
245245
return static::validateLength($control, [null, $length]);
246246
}
@@ -357,7 +357,7 @@ public static function validateFloat(Control $control): bool
357357
/**
358358
* Checks whether all uploaded files are within the size limit (in bytes).
359359
*/
360-
public static function validateFileSize(Controls\UploadControl $control, $limit): bool
360+
public static function validateFileSize(Controls\UploadControl $control, int $limit): bool
361361
{
362362
foreach (static::toArray($control->getValue()) as $file) {
363363
if ($file->getSize() > $limit || $file->getError() === UPLOAD_ERR_INI_SIZE) {
@@ -403,7 +403,7 @@ public static function validateImage(Controls\UploadControl $control): bool
403403

404404

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

0 commit comments

Comments
 (0)