Skip to content

Commit b9f4038

Browse files
committed
added missing native types
1 parent 6ab5aa3 commit b9f4038

11 files changed

Lines changed: 36 additions & 33 deletions

File tree

src/Bridges/FormsLatte/Runtime.php

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

8080

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

src/Forms/Container.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ public function addFloat(string $name, string|Stringable|null $label = null): Co
405405
/**
406406
* Adds input for date selection.
407407
*/
408-
public function addDate(string $name, string|object|null $label = null): Controls\DateTimeControl
408+
public function addDate(string $name, string|Stringable|null $label = null): Controls\DateTimeControl
409409
{
410410
return $this[$name] = new Controls\DateTimeControl($label, Controls\DateTimeControl::TypeDate);
411411
}
@@ -416,7 +416,7 @@ public function addDate(string $name, string|object|null $label = null): Control
416416
*/
417417
public function addTime(
418418
string $name,
419-
string|object|null $label = null,
419+
string|Stringable|null $label = null,
420420
bool $withSeconds = false,
421421
): Controls\DateTimeControl
422422
{
@@ -429,7 +429,7 @@ public function addTime(
429429
*/
430430
public function addDateTime(
431431
string $name,
432-
string|object|null $label = null,
432+
string|Stringable|null $label = null,
433433
bool $withSeconds = false,
434434
): Controls\DateTimeControl
435435
{
@@ -458,7 +458,7 @@ public function addMultiUpload(string $name, string|Stringable|null $label = nul
458458
/**
459459
* Adds hidden form control used to store a non-displayed value.
460460
*/
461-
public function addHidden(string $name, $default = null): Controls\HiddenField
461+
public function addHidden(string $name, mixed $default = null): Controls\HiddenField
462462
{
463463
return $this[$name] = (new Controls\HiddenField)
464464
->setDefaultValue($default);
@@ -595,7 +595,7 @@ public function addContainer(string|int $name): self
595595

596596

597597
/** @param mixed[] $args */
598-
public function __call(string $name, array $args)
598+
public function __call(string $name, array $args): mixed
599599
{
600600
if (isset(self::$extMethods[$name])) {
601601
return (self::$extMethods[$name])($this, ...$args);

src/Forms/ControlGroup.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function __construct()
3232

3333

3434
/** @param Control|Container|iterable<Control|Container> ...$items */
35-
public function add(...$items): static
35+
public function add(Control|Container|iterable ...$items): static
3636
{
3737
foreach ($items as $item) {
3838
if ($item instanceof Control) {

src/Forms/Controls/BaseControl.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ abstract class BaseControl extends Nette\ComponentModel\Component implements Con
5959
private Rules $rules;
6060

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

6464
/** @var array<string, mixed> */
6565
private array $options = [];
@@ -172,7 +172,7 @@ public function isFilled(): bool
172172
* Sets control's default value.
173173
* @return static
174174
*/
175-
public function setDefaultValue($value)
175+
public function setDefaultValue(mixed $value)
176176
{
177177
$form = $this->getForm(throw: false);
178178
if ($this->isDisabled() || !$form || !$form->isAnchored() || !$form->isSubmitted()) {
@@ -381,7 +381,7 @@ public function getTranslator(): ?Nette\Localization\Translator
381381
/**
382382
* Returns translated string.
383383
*/
384-
public function translate($value, ...$parameters): mixed
384+
public function translate(mixed $value, mixed ...$parameters): mixed
385385
{
386386
if ($translator = $this->getTranslator()) {
387387
$tmp = is_array($value) ? [&$value] : [[&$value]];
@@ -418,7 +418,7 @@ public function addRule(
418418
* Adds a validation condition a returns new branch.
419419
* @param (callable(self): bool)|string|bool $validator
420420
*/
421-
public function addCondition($validator, $value = null): Rules
421+
public function addCondition($validator, mixed $value = null): Rules
422422
{
423423
return $this->rules->addCondition($validator, $value);
424424
}
@@ -428,7 +428,7 @@ public function addCondition($validator, $value = null): Rules
428428
* Adds a validation condition based on another control a returns new branch.
429429
* @param (callable(self): bool)|string $validator
430430
*/
431-
public function addConditionOn(Control $control, $validator, $value = null): Rules
431+
public function addConditionOn(Control $control, $validator, mixed $value = null): Rules
432432
{
433433
return $this->rules->addConditionOn($control, $validator, $value);
434434
}

src/Forms/Controls/HiddenField.php

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

2626

27-
public function __construct($persistentValue = null)
27+
public function __construct(mixed $persistentValue = null)
2828
{
2929
parent::__construct();
3030
$this->control->type = 'hidden';

src/Forms/Controls/MultiSelectBox.php

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

2727

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

src/Forms/Form.php

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

524524

525525
/** @param iterable<callable> $handlers */
526-
private function invokeHandlers(iterable $handlers, $button = null): void
526+
private function invokeHandlers(iterable $handlers, ?SubmitterControl $button = null): void
527527
{
528528
foreach ($handlers as $handler) {
529529
$params = Nette\Utils\Callback::toReflection($handler)->getParameters();
@@ -732,7 +732,7 @@ public function fireRenderEvents(): void
732732
/**
733733
* Renders form.
734734
*/
735-
public function render(...$args): void
735+
public function render(mixed ...$args): void
736736
{
737737
$this->fireRenderEvents();
738738
echo $this->getRenderer()->render($this, ...$args);

src/Forms/Helpers.php

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

7272

7373
/** @return string|mixed[]|Nette\Http\FileUpload|null */
74-
private static function sanitize(int $type, $value): string|array|Nette\Http\FileUpload|null
74+
private static function sanitize(int $type, mixed $value): string|array|Nette\Http\FileUpload|null
7575
{
7676
if ($type === Form::DataText) {
7777
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');
@@ -221,7 +221,7 @@ public static function createInputList(
221221
* @param mixed[] $items
222222
* @param ?array<string, mixed> $optionAttrs
223223
*/
224-
public static function createSelectBox(array $items, ?array $optionAttrs = null, $selected = null): Html
224+
public static function createSelectBox(array $items, ?array $optionAttrs = null, mixed $selected = null): Html
225225
{
226226
if ($selected !== null) {
227227
$optionAttrs['selected?'] = $selected;
@@ -306,7 +306,7 @@ public static function iniGetSize(string $name): int
306306
* @internal
307307
* @return ?class-string
308308
*/
309-
public static function getSingleType($reflection): ?string
309+
public static function getSingleType(\ReflectionParameter|\ReflectionProperty $reflection): ?string
310310
{
311311
$type = Nette\Utils\Type::fromReflection($reflection);
312312
if (!$type) {
@@ -322,7 +322,10 @@ public static function getSingleType($reflection): ?string
322322

323323

324324
/** @internal */
325-
public static function tryEnumConversion(mixed $value, $reflection): mixed
325+
public static function tryEnumConversion(
326+
mixed $value,
327+
\ReflectionParameter|\ReflectionProperty|null $reflection,
328+
): mixed
326329
{
327330
if ($value !== null
328331
&& $reflection

src/Forms/Rules.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public function removeRule(callable|string $validator): static
119119
* Adds a validation condition and returns new branch.
120120
* @param (callable(Control): bool)|string|bool $validator
121121
*/
122-
public function addCondition($validator, $arg = null): static
122+
public function addCondition(callable|string|bool $validator, mixed $arg = null): static
123123
{
124124
if ($validator === Form::Valid || $validator === ~Form::Valid) {
125125
throw new Nette\InvalidArgumentException('You cannot use Form::Valid in the addCondition method.');
@@ -136,7 +136,7 @@ public function addCondition($validator, $arg = null): static
136136
* Adds a validation condition on specified control a returns new branch.
137137
* @param (callable(Control): bool)|string $validator
138138
*/
139-
public function addConditionOn(Control $control, $validator, $arg = null): static
139+
public function addConditionOn(Control $control, callable|string $validator, mixed $arg = null): static
140140
{
141141
$rule = new Rule;
142142
$rule->control = $control;
@@ -347,7 +347,7 @@ private function adjustOperation(Rule $rule): void
347347
}
348348

349349

350-
private static function getCallback(Rule $rule)
350+
private static function getCallback(Rule $rule): array|callable|string
351351
{
352352
$op = $rule->validator;
353353
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
@@ -115,7 +115,7 @@ public static function formatMessage(Rule $rule, bool $withValue = true): string
115115
/**
116116
* Is control's value equal with second parameter?
117117
*/
118-
public static function validateEqual(Control $control, $arg): bool
118+
public static function validateEqual(Control $control, mixed $arg): bool
119119
{
120120
$value = $control->getValue();
121121
$values = is_array($value) ? $value : [$value];
@@ -142,7 +142,7 @@ public static function validateEqual(Control $control, $arg): bool
142142
/**
143143
* Is control's value not equal with second parameter?
144144
*/
145-
public static function validateNotEqual(Control $control, $arg): bool
145+
public static function validateNotEqual(Control $control, mixed $arg): bool
146146
{
147147
return !static::validateEqual($control, $arg);
148148
}
@@ -201,7 +201,7 @@ public static function validateRange(Control $control, array $range): bool
201201
/**
202202
* Is a control's value number greater than or equal to the specified minimum?
203203
*/
204-
public static function validateMin(Control $control, $minimum): bool
204+
public static function validateMin(Control $control, int|float|string|\DateTimeInterface $minimum): bool
205205
{
206206
return Validators::isInRange($control->getValue(), [$minimum === '' ? null : $minimum, null]);
207207
}
@@ -210,7 +210,7 @@ public static function validateMin(Control $control, $minimum): bool
210210
/**
211211
* Is a control's value number less than or equal to the specified maximum?
212212
*/
213-
public static function validateMax(Control $control, $maximum): bool
213+
public static function validateMax(Control $control, int|float|string|\DateTimeInterface $maximum): bool
214214
{
215215
return Validators::isInRange($control->getValue(), [null, $maximum === '' ? null : $maximum]);
216216
}
@@ -234,7 +234,7 @@ public static function validateLength(Control $control, array|int $range): bool
234234
/**
235235
* Has control's value minimal count/length?
236236
*/
237-
public static function validateMinLength(Control $control, $length): bool
237+
public static function validateMinLength(Control $control, int $length): bool
238238
{
239239
return static::validateLength($control, [$length, null]);
240240
}
@@ -243,7 +243,7 @@ public static function validateMinLength(Control $control, $length): bool
243243
/**
244244
* Is control's value count/length in limit?
245245
*/
246-
public static function validateMaxLength(Control $control, $length): bool
246+
public static function validateMaxLength(Control $control, int $length): bool
247247
{
248248
return static::validateLength($control, [null, $length]);
249249
}
@@ -361,7 +361,7 @@ public static function validateFloat(Control $control): bool
361361
/**
362362
* Is file size in limit?
363363
*/
364-
public static function validateFileSize(Controls\UploadControl $control, $limit): bool
364+
public static function validateFileSize(Controls\UploadControl $control, int $limit): bool
365365
{
366366
foreach (static::toArray($control->getValue()) as $file) {
367367
if ($file->getSize() > $limit || $file->getError() === UPLOAD_ERR_INI_SIZE) {
@@ -407,7 +407,7 @@ public static function validateImage(Controls\UploadControl $control): bool
407407

408408

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

0 commit comments

Comments
 (0)