Skip to content

Commit fc0342a

Browse files
committed
added missing typehints
1 parent 5141f9b commit fc0342a

9 files changed

+15
-21
lines changed

examples/custom-control.php

+1-7
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,14 @@ public function setValue($value)
4848
}
4949

5050

51-
/**
52-
* @return DateTimeImmutable|null
53-
*/
54-
public function getValue()
51+
public function getValue(): ?DateTimeImmutable
5552
{
5653
return self::validateDate($this)
5754
? (new DateTimeImmutable)->setDate((int) $this->year, (int) $this->month, (int) $this->day)->setTime(0, 0)
5855
: null;
5956
}
6057

6158

62-
/**
63-
* @return bool
64-
*/
6559
public function isFilled(): bool
6660
{
6761
return $this->day !== '' || $this->year !== '';

src/Forms/Container.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class Container extends Nette\ComponentModel\Container implements \ArrayAccess
2323
{
2424
use Nette\ComponentModel\ArrayAccess;
2525

26-
/** @var callable[] function (Container $sender); Occurs when the form is validated */
26+
/** @var callable[] function (Container $sender): void; Occurs when the form is validated */
2727
public $onValidate;
2828

2929
/** @var ControlGroup|null */

src/Forms/Controls/BaseControl.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public function __construct($caption = null)
9191
$this->setRequired(false);
9292
}
9393
$this->setValue(null);
94-
$this->monitor(Form::class, function (Form $form) {
94+
$this->monitor(Form::class, function (Form $form): void {
9595
if (!$this->isDisabled() && $form->isAnchored() && $form->isSubmitted()) {
9696
$this->loadHttpData();
9797
}

src/Forms/Controls/CsrfProtection.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function __construct($errorMessage)
3434
->setRequired()
3535
->addRule(self::PROTECTION, $errorMessage);
3636

37-
$this->monitor(Presenter::class, function (Presenter $presenter) {
37+
$this->monitor(Presenter::class, function (Presenter $presenter): void {
3838
if (!$this->session) {
3939
$this->session = $presenter->getSession();
4040
}

src/Forms/Controls/SubmitButton.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919
*/
2020
class SubmitButton extends Button implements Nette\Forms\ISubmitterControl
2121
{
22-
/** @var callable[] function (SubmitButton $sender); Occurs when the button is clicked and form is successfully validated */
22+
/** @var callable[] function (SubmitButton $sender): void; Occurs when the button is clicked and form is successfully validated */
2323
public $onClick;
2424

25-
/** @var callable[] function (SubmitButton $sender); Occurs when the button is clicked and form is not validated */
25+
/** @var callable[] function (SubmitButton $sender): void; Occurs when the button is clicked and form is not validated */
2626
public $onInvalidClick;
2727

2828
/** @var array|null */

src/Forms/Controls/UploadControl.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function __construct($label = null, bool $multiple = false)
3535
$this->addCondition(Forms\Form::FILLED)
3636
->addRule([$this, 'isOk'], Forms\Validator::$messages[self::VALID]);
3737

38-
$this->monitor(Forms\Form::class, function (Forms\Form $form) {
38+
$this->monitor(Forms\Form::class, function (Forms\Form $form): void {
3939
if (!$form->isMethod('post')) {
4040
throw new Nette\InvalidStateException('File upload requires method POST.');
4141
}
@@ -93,7 +93,7 @@ public function isOk(): bool
9393
{
9494
return $this->value instanceof FileUpload
9595
? $this->value->isOk()
96-
: $this->value && array_reduce($this->value, function ($carry, $fileUpload) {
96+
: $this->value && array_reduce($this->value, function (bool $carry, FileUpload $fileUpload): bool {
9797
return $carry && $fileUpload->isOk();
9898
}, true);
9999
}

src/Forms/Form.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,16 @@ class Form extends Container implements Nette\Utils\IHtmlString
8181
/** @internal protection token ID */
8282
public const PROTECTOR_ID = '_token_';
8383

84-
/** @var callable[] function (Form $sender); Occurs when the form is submitted and successfully validated */
84+
/** @var callable[] function (Form $sender): void; Occurs when the form is submitted and successfully validated */
8585
public $onSuccess;
8686

87-
/** @var callable[] function (Form $sender); Occurs when the form is submitted and is not valid */
87+
/** @var callable[] function (Form $sender): void; Occurs when the form is submitted and is not valid */
8888
public $onError;
8989

90-
/** @var callable[] function (Form $sender); Occurs when the form is submitted */
90+
/** @var callable[] function (Form $sender): void; Occurs when the form is submitted */
9191
public $onSubmit;
9292

93-
/** @var callable[] function (Form $sender); Occurs before the form is rendered */
93+
/** @var callable[] function (Form $sender): void; Occurs before the form is rendered */
9494
public $onRender;
9595

9696
/** @var Nette\Http\IRequest used only by standalone form */
@@ -133,7 +133,7 @@ public function __construct(string $name = null)
133133
$this[self::TRACKER_ID] = $tracker;
134134
$this->setParent(null, $name);
135135
}
136-
$this->monitor(__CLASS__, function () {
136+
$this->monitor(__CLASS__, function (): void {
137137
throw new Nette\InvalidStateException('Nested forms are forbidden.');
138138
});
139139
}

src/Forms/Rules.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ public function addFilter(callable $filter)
169169
{
170170
$this->rules[] = $rule = new Rule;
171171
$rule->control = $this->control;
172-
$rule->validator = function (IControl $control) use ($filter) {
172+
$rule->validator = function (IControl $control) use ($filter): bool {
173173
$control->setValue($filter($control->getValue()));
174174
return true;
175175
};

src/Forms/Validator.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public static function formatMessage(Rule $rule, bool $withValue = true)
6565
$message = $translator->translate($message, is_int($rule->arg) ? $rule->arg : null);
6666
}
6767

68-
$message = preg_replace_callback('#%(name|label|value|\d+\$[ds]|[ds])#', function ($m) use ($rule, $withValue) {
68+
$message = preg_replace_callback('#%(name|label|value|\d+\$[ds]|[ds])#', function (array $m) use ($rule, $withValue) {
6969
static $i = -1;
7070
switch ($m[1]) {
7171
case 'name': return $rule->control->getName();

0 commit comments

Comments
 (0)