diff --git a/src/Forms/Container.php b/src/Forms/Container.php index 858ddf5df..e0b176031 100644 --- a/src/Forms/Container.php +++ b/src/Forms/Container.php @@ -110,7 +110,7 @@ public function setValues($data, bool $erase = false) * @param Control[]|null $controls * @return object|array */ - public function getValues($returnType = null, array $controls = null) + public function getValues($returnType = null, ?array $controls = null) { $form = $this->getForm(false); if ($form && ($submitter = $form->isSubmitted())) { @@ -137,7 +137,7 @@ public function getValues($returnType = null, array $controls = null) * @param Control[]|null $controls * @return object|array */ - public function getUnsafeValues($returnType, array $controls = null) + public function getUnsafeValues($returnType, ?array $controls = null) { if (is_object($returnType)) { $obj = $returnType; @@ -217,7 +217,7 @@ public function isValid(): bool * Performs the server side validation. * @param Control[]|null $controls */ - public function validate(array $controls = null): void + public function validate(?array $controls = null): void { $this->validated = null; foreach ($controls ?? $this->getComponents() as $control) { @@ -257,7 +257,7 @@ public function getErrors(): array /** @return static */ - public function setCurrentGroup(ControlGroup $group = null) + public function setCurrentGroup(?ControlGroup $group = null) { $this->currentGroup = $group; return $this; @@ -278,7 +278,7 @@ public function getCurrentGroup(): ?ControlGroup * @return static * @throws Nette\InvalidStateException */ - public function addComponent(Nette\ComponentModel\IComponent $component, ?string $name, string $insertBefore = null) + public function addComponent(Nette\ComponentModel\IComponent $component, ?string $name, ?string $insertBefore = null) { parent::addComponent($component, $name, $insertBefore); if ($this->currentGroup !== null) { @@ -314,7 +314,7 @@ public function getForm(bool $throw = true): ?Form * Adds single-line text input control to the form. * @param string|object $label */ - public function addText(string $name, $label = null, int $cols = null, int $maxLength = null): Controls\TextInput + public function addText(string $name, $label = null, ?int $cols = null, ?int $maxLength = null): Controls\TextInput { return $this[$name] = (new Controls\TextInput($label, $maxLength)) ->setHtmlAttribute('size', $cols); @@ -328,8 +328,8 @@ public function addText(string $name, $label = null, int $cols = null, int $maxL public function addPassword( string $name, $label = null, - int $cols = null, - int $maxLength = null + ?int $cols = null, + ?int $maxLength = null ): Controls\TextInput { return $this[$name] = (new Controls\TextInput($label, $maxLength)) ->setHtmlAttribute('size', $cols) @@ -341,7 +341,7 @@ public function addPassword( * Adds multi-line text input control to the form. * @param string|object $label */ - public function addTextArea(string $name, $label = null, int $cols = null, int $rows = null): Controls\TextArea + public function addTextArea(string $name, $label = null, ?int $cols = null, ?int $rows = null): Controls\TextArea { return $this[$name] = (new Controls\TextArea($label)) ->setHtmlAttribute('cols', $cols)->setHtmlAttribute('rows', $rows); @@ -415,7 +415,7 @@ public function addCheckbox(string $name, $caption = null): Controls\Checkbox * Adds set of radio button controls to the form. * @param string|object $label */ - public function addRadioList(string $name, $label = null, array $items = null): Controls\RadioList + public function addRadioList(string $name, $label = null, ?array $items = null): Controls\RadioList { return $this[$name] = new Controls\RadioList($label, $items); } @@ -425,7 +425,7 @@ public function addRadioList(string $name, $label = null, array $items = null): * Adds set of checkbox controls to the form. * @param string|object $label */ - public function addCheckboxList(string $name, $label = null, array $items = null): Controls\CheckboxList + public function addCheckboxList(string $name, $label = null, ?array $items = null): Controls\CheckboxList { return $this[$name] = new Controls\CheckboxList($label, $items); } @@ -435,7 +435,7 @@ public function addCheckboxList(string $name, $label = null, array $items = null * Adds select box control that allows single item selection. * @param string|object $label */ - public function addSelect(string $name, $label = null, array $items = null, int $size = null): Controls\SelectBox + public function addSelect(string $name, $label = null, ?array $items = null, ?int $size = null): Controls\SelectBox { return $this[$name] = (new Controls\SelectBox($label, $items)) ->setHtmlAttribute('size', $size > 1 ? $size : null); @@ -449,8 +449,8 @@ public function addSelect(string $name, $label = null, array $items = null, int public function addMultiSelect( string $name, $label = null, - array $items = null, - int $size = null + ?array $items = null, + ?int $size = null ): Controls\MultiSelectBox { return $this[$name] = (new Controls\MultiSelectBox($label, $items)) ->setHtmlAttribute('size', $size > 1 ? $size : null); @@ -482,7 +482,7 @@ public function addButton(string $name, $caption = null): Controls\Button * @param string $src URI of the image * @param string $alt alternate text for the image */ - public function addImageButton(string $name, string $src = null, string $alt = null): Controls\ImageButton + public function addImageButton(string $name, ?string $src = null, ?string $alt = null): Controls\ImageButton { return $this[$name] = new Controls\ImageButton($src, $alt); } diff --git a/src/Forms/Controls/BaseControl.php b/src/Forms/Controls/BaseControl.php index 7a7f9a3d4..41defb7fa 100644 --- a/src/Forms/Controls/BaseControl.php +++ b/src/Forms/Controls/BaseControl.php @@ -134,7 +134,7 @@ public function loadHttpData(): void * Loads HTTP data. * @return mixed */ - protected function getHttpData($type, string $htmlTail = null) + protected function getHttpData($type, ?string $htmlTail = null) { return $this->getForm()->getHttpData($type, $this->getHtmlName() . $htmlTail); } diff --git a/src/Forms/Controls/CheckboxList.php b/src/Forms/Controls/CheckboxList.php index c933ca26c..dd058db80 100644 --- a/src/Forms/Controls/CheckboxList.php +++ b/src/Forms/Controls/CheckboxList.php @@ -35,7 +35,7 @@ class CheckboxList extends MultiChoiceControl /** * @param string|object $label */ - public function __construct($label = null, array $items = null) + public function __construct($label = null, ?array $items = null) { parent::__construct($label, $items); $this->control->type = 'checkbox'; diff --git a/src/Forms/Controls/ChoiceControl.php b/src/Forms/Controls/ChoiceControl.php index 6e890f0e3..c9b652f39 100644 --- a/src/Forms/Controls/ChoiceControl.php +++ b/src/Forms/Controls/ChoiceControl.php @@ -27,7 +27,7 @@ abstract class ChoiceControl extends BaseControl private $items = []; - public function __construct($label = null, array $items = null) + public function __construct($label = null, ?array $items = null) { parent::__construct($label); if ($items !== null) { diff --git a/src/Forms/Controls/CsrfProtection.php b/src/Forms/Controls/CsrfProtection.php index a2db72c9a..1c4bf2ac5 100644 --- a/src/Forms/Controls/CsrfProtection.php +++ b/src/Forms/Controls/CsrfProtection.php @@ -81,7 +81,7 @@ public function getToken(): string } - private function generateToken(string $random = null): string + private function generateToken(?string $random = null): string { if ($random === null) { $random = Nette\Utils\Random::generate(10); diff --git a/src/Forms/Controls/ImageButton.php b/src/Forms/Controls/ImageButton.php index d326e9c18..035fcbe0b 100644 --- a/src/Forms/Controls/ImageButton.php +++ b/src/Forms/Controls/ImageButton.php @@ -19,7 +19,7 @@ class ImageButton extends SubmitButton * @param string $src URI of the image * @param string $alt alternate text for the image */ - public function __construct(string $src = null, string $alt = null) + public function __construct(?string $src = null, ?string $alt = null) { parent::__construct(); $this->control->type = 'image'; diff --git a/src/Forms/Controls/MultiChoiceControl.php b/src/Forms/Controls/MultiChoiceControl.php index 5a223d026..2d0d71878 100644 --- a/src/Forms/Controls/MultiChoiceControl.php +++ b/src/Forms/Controls/MultiChoiceControl.php @@ -27,7 +27,7 @@ abstract class MultiChoiceControl extends BaseControl private $items = []; - public function __construct($label = null, array $items = null) + public function __construct($label = null, ?array $items = null) { parent::__construct($label); if ($items !== null) { diff --git a/src/Forms/Controls/MultiSelectBox.php b/src/Forms/Controls/MultiSelectBox.php index 5bcfc64bc..c154de1f4 100644 --- a/src/Forms/Controls/MultiSelectBox.php +++ b/src/Forms/Controls/MultiSelectBox.php @@ -24,7 +24,7 @@ class MultiSelectBox extends MultiChoiceControl private $optionAttributes = []; - public function __construct($label = null, array $items = null) + public function __construct($label = null, ?array $items = null) { parent::__construct($label, $items); $this->setOption('type', 'select'); diff --git a/src/Forms/Controls/RadioList.php b/src/Forms/Controls/RadioList.php index 233f40ae1..5a9282b0b 100644 --- a/src/Forms/Controls/RadioList.php +++ b/src/Forms/Controls/RadioList.php @@ -38,7 +38,7 @@ class RadioList extends ChoiceControl /** * @param string|object $label */ - public function __construct($label = null, array $items = null) + public function __construct($label = null, ?array $items = null) { parent::__construct($label, $items); $this->control->type = 'radio'; diff --git a/src/Forms/Controls/SelectBox.php b/src/Forms/Controls/SelectBox.php index a33c9ac28..8d69f6e38 100644 --- a/src/Forms/Controls/SelectBox.php +++ b/src/Forms/Controls/SelectBox.php @@ -30,7 +30,7 @@ class SelectBox extends ChoiceControl private $optionAttributes = []; - public function __construct($label = null, array $items = null) + public function __construct($label = null, ?array $items = null) { parent::__construct($label, $items); $this->setOption('type', 'select'); diff --git a/src/Forms/Controls/TextInput.php b/src/Forms/Controls/TextInput.php index e497e6b9f..78696f490 100644 --- a/src/Forms/Controls/TextInput.php +++ b/src/Forms/Controls/TextInput.php @@ -21,7 +21,7 @@ class TextInput extends TextBase /** * @param string|object $label */ - public function __construct($label = null, int $maxLength = null) + public function __construct($label = null, ?int $maxLength = null) { parent::__construct($label); $this->control->maxlength = $maxLength; diff --git a/src/Forms/Form.php b/src/Forms/Form.php index 45587a9cf..070e486b3 100644 --- a/src/Forms/Form.php +++ b/src/Forms/Form.php @@ -131,7 +131,7 @@ class Form extends Container implements Nette\HtmlStringable private $beforeRenderCalled; - public function __construct(string $name = null) + public function __construct(?string $name = null) { if ($name !== null) { $this->getElementPrototype()->id = 'frm-' . $name; @@ -235,7 +235,7 @@ public function allowCrossOrigin(): void /** * Cross-Site Request Forgery (CSRF) form protection. */ - public function addProtection(string $errorMessage = null): Controls\CsrfProtection + public function addProtection(?string $errorMessage = null): Controls\CsrfProtection { $control = new Controls\CsrfProtection($errorMessage); $this->addComponent($control, self::PROTECTOR_ID, key((array) $this->getComponents())); @@ -382,7 +382,7 @@ public function setSubmittedBy(?SubmitterControl $by) * Returns submitted HTTP data. * @return mixed */ - public function getHttpData(int $type = null, string $htmlName = null) + public function getHttpData(?int $type = null, ?string $htmlName = null) { if ($this->httpData === null) { if (!$this->isAnchored()) { @@ -514,7 +514,7 @@ protected function receiveHttpData(): ?array /********************* validation ****************d*g**/ - public function validate(array $controls = null): void + public function validate(?array $controls = null): void { $this->cleanErrors(); if ($controls === null && $this->submittedBy instanceof SubmitterControl) { diff --git a/src/Forms/Helpers.php b/src/Forms/Helpers.php index a1c899b18..59c42e9cf 100644 --- a/src/Forms/Helpers.php +++ b/src/Forms/Helpers.php @@ -160,8 +160,8 @@ public static function exportRules(Rules $rules): array public static function createInputList( array $items, - array $inputAttrs = null, - array $labelAttrs = null, + ?array $inputAttrs = null, + ?array $labelAttrs = null, $wrapper = null ): string { [$inputAttrs, $inputTag] = self::prepareAttrs($inputAttrs, 'input'); @@ -193,7 +193,7 @@ public static function createInputList( } - public static function createSelectBox(array $items, array $optionAttrs = null, $selected = null): Html + public static function createSelectBox(array $items, ?array $optionAttrs = null, $selected = null): Html { if ($selected !== null) { $optionAttrs['selected?'] = $selected; diff --git a/src/Forms/Rendering/DataClassGenerator.php b/src/Forms/Rendering/DataClassGenerator.php index fdb6358d4..0c56a63eb 100644 --- a/src/Forms/Rendering/DataClassGenerator.php +++ b/src/Forms/Rendering/DataClassGenerator.php @@ -29,7 +29,7 @@ final class DataClassGenerator public $useSmartObject = true; - public function generateCode(Form $form, string $baseName = null): string + public function generateCode(Form $form, ?string $baseName = null): string { $baseName = $baseName ?? preg_replace('~Form$~', '', ucwords((string) $form->getName())); return $this->processContainer($form, $baseName); diff --git a/src/Forms/Rendering/DefaultFormRenderer.php b/src/Forms/Rendering/DefaultFormRenderer.php index 6be8ea4cd..8ee515106 100644 --- a/src/Forms/Rendering/DefaultFormRenderer.php +++ b/src/Forms/Rendering/DefaultFormRenderer.php @@ -129,7 +129,7 @@ class DefaultFormRenderer implements Nette\Forms\FormRenderer * Provides complete form rendering. * @param string $mode 'begin', 'errors', 'ownerrors', 'body', 'end' or empty to render all */ - public function render(Nette\Forms\Form $form, string $mode = null): string + public function render(Nette\Forms\Form $form, ?string $mode = null): string { if ($this->form !== $form) { $this->form = $form; @@ -220,7 +220,7 @@ public function renderEnd(): string /** * Renders validation errors (per form or per control). */ - public function renderErrors(Nette\Forms\Control $control = null, bool $own = true): string + public function renderErrors(?Nette\Forms\Control $control = null, bool $own = true): string { $errors = $control ? $control->getErrors() diff --git a/src/Forms/Rules.php b/src/Forms/Rules.php index bee4ae63b..f41bbbb66 100644 --- a/src/Forms/Rules.php +++ b/src/Forms/Rules.php @@ -221,7 +221,7 @@ public function getToggles(bool $actual = false): array /** @internal */ - public function getToggleStates(array $toggles = [], bool $success = true, bool $emptyOptional = null): array + public function getToggleStates(array $toggles = [], bool $success = true, ?bool $emptyOptional = null): array { foreach ($this->toggles as $id => $hide) { $toggles[$id] = ($success xor !$hide) || !empty($toggles[$id]); @@ -247,7 +247,7 @@ public function getToggleStates(array $toggles = [], bool $success = true, bool /** * Validates against ruleset. */ - public function validate(bool $emptyOptional = null): bool + public function validate(?bool $emptyOptional = null): bool { $emptyOptional = $emptyOptional ?? (!$this->isRequired() && !$this->control->isFilled()); foreach ($this as $rule) { diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 039552af1..abb911275 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -15,7 +15,7 @@ date_default_timezone_set('Europe/Prague'); -function before(Closure $function = null) +function before(?Closure $function = null) { static $val; if (!func_num_args()) {