Skip to content

Commit

Permalink
cs nullable typehints
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Dec 12, 2021
1 parent fd785f8 commit 78c7ec6
Show file tree
Hide file tree
Showing 17 changed files with 38 additions and 38 deletions.
30 changes: 15 additions & 15 deletions src/Forms/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -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())) {
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -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);
Expand All @@ -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)
Expand All @@ -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);
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Forms/Controls/BaseControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Forms/Controls/CheckboxList.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion src/Forms/Controls/ChoiceControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/Forms/Controls/CsrfProtection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/Forms/Controls/ImageButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion src/Forms/Controls/MultiChoiceControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/Forms/Controls/MultiSelectBox.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion src/Forms/Controls/RadioList.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion src/Forms/Controls/SelectBox.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion src/Forms/Controls/TextInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions src/Forms/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()));
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions src/Forms/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Forms/Rendering/DataClassGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/Forms/Rendering/DefaultFormRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions src/Forms/Rules.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down

0 comments on commit 78c7ec6

Please sign in to comment.