Skip to content

Commit

Permalink
Fix nullable parameter type for PHP 8.4 (#2185)
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek authored Mar 19, 2024
1 parent 75497db commit 5fc79ed
Show file tree
Hide file tree
Showing 51 changed files with 103 additions and 110 deletions.
3 changes: 0 additions & 3 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@
'general_phpdoc_annotation_remove' => [
'annotations' => ['author', 'copyright', 'throws'],
],
'nullable_type_declaration_for_default_null_value' => [
'use_nullable_type_declaration' => false,
],

// fn => without curly brackets is less readable,
// also prevent bounding of unwanted variables for GC
Expand Down
2 changes: 1 addition & 1 deletion demos/form/form2.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ protected function init(): void
}

#[\Override]
public function validate(string $intent = null): array
public function validate(?string $intent = null): array
{
$errors = parent::validate($intent);

Expand Down
4 changes: 2 additions & 2 deletions demos/init-db.php
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ protected function init(): void
}

#[\Override]
public function validate(string $intent = null): array
public function validate(?string $intent = null): array
{
$errors = parent::validate($intent);

Expand Down Expand Up @@ -502,7 +502,7 @@ protected function init(): void
->addTitle();
}

public function importFromFilesystem(string $path, bool $isSub = null): void
public function importFromFilesystem(string $path, ?bool $isSub = null): void
{
if ($isSub === null) {
if ($this->isEntity()) { // TODO should be not needed once UserAction is for non-entity only
Expand Down
2 changes: 1 addition & 1 deletion demos/interactive/popup.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ protected function init(): void
* Associate your shelf with cart, so that when item is clicked, the content of a
* cart is updated.
*/
public function linkCart(View $cart, JsExpressionable $jsAction = null): void
public function linkCart(View $cart, ?JsExpressionable $jsAction = null): void
{
$this->on('click', '.item', static function (Jquery $a, string $b) use ($cart, $jsAction) {
$cart->addItem($b);
Expand Down
2 changes: 1 addition & 1 deletion src/Accordion.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class Accordion extends View
*
* @return AccordionSection
*/
public function addSection($title, \Closure $callback = null, $icon = 'dropdown')
public function addSection($title, ?\Closure $callback = null, $icon = 'dropdown')
{
$section = AccordionSection::addTo($this, ['title' => $title, 'icon' => $icon]);

Expand Down
2 changes: 1 addition & 1 deletion src/App/SessionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public function learn(string $namespace, string $key, $defaultValue = null)
* Forget session data for $key. If $key is omitted will forget all
* associated session data.
*/
public function forget(string $namespace, string $key = null): void
public function forget(string $namespace, ?string $key = null): void
{
$this->atomicSession(function () use ($namespace, $key) {
if ($key === null) {
Expand Down
2 changes: 1 addition & 1 deletion src/Behat/MinkSeleniumDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ protected function mouseOverElement(WebDriverElement $element): void
$this->getWebDriverSession()->moveto(['element' => $element->getID()]);
}

private function executeJsSelectText(WebDriverElement $element, int $start, int $stop = null): void
private function executeJsSelectText(WebDriverElement $element, int $start, ?int $stop = null): void
{
$this->executeScript(
'arguments[0].setSelectionRange(Math.min(arguments[1], Number.MAX_SAFE_INTEGER), Math.min(arguments[2], Number.MAX_SAFE_INTEGER));',
Expand Down
4 changes: 2 additions & 2 deletions src/Callback.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ protected function init(): void
$this->setUrlTrigger($this->urlTrigger);
}

public function setUrlTrigger(string $trigger = null): void
public function setUrlTrigger(?string $trigger = null): void
{
$this->urlTrigger = $trigger ?? $this->name;

Expand Down Expand Up @@ -147,7 +147,7 @@ public function getUrl(string $value = 'callback'): string
/**
* Return proper URL argument for this callback.
*/
private function getUrlArguments(string $value = null): array
private function getUrlArguments(?string $value = null): array
{
return [
self::URL_QUERY_TARGET => $this->urlTrigger,
Expand Down
8 changes: 4 additions & 4 deletions src/Card.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public function addContent(View $view)
* @param array<int, string>|null $fields
*/
#[\Override]
public function setModel(Model $entity, array $fields = null): void
public function setModel(Model $entity, ?array $fields = null): void
{
$entity->assertIsLoaded();

Expand All @@ -188,7 +188,7 @@ public function setModel(Model $entity, array $fields = null): void
*
* @return View
*/
public function addSection(string $title = null, Model $model = null, array $fields = null, bool $useTable = false, bool $useLabel = false)
public function addSection(?string $title = null, ?Model $model = null, ?array $fields = null, bool $useTable = false, bool $useLabel = false)
{
$section = CardSection::addToWithCl($this, array_merge($this->cardSectionSeed, ['card' => $this]), ['Section']);
if ($title) {
Expand All @@ -208,7 +208,7 @@ public function addSection(string $title = null, Model $model = null, array $fie
*
* @return $this
*/
public function addClickAction(Model\UserAction $action, Button $button = null, array $args = [], string $confirm = null): self
public function addClickAction(Model\UserAction $action, ?Button $button = null, array $args = [], ?string $confirm = null): self
{
$button = $this->addButton($button ?? $this->getExecutorFactory()->createTrigger($action, ExecutorFactory::CARD_BUTTON));

Expand Down Expand Up @@ -257,7 +257,7 @@ public function addClickAction(Model\UserAction $action, Button $button = null,
/**
* Set extra content using model field.
*/
public function addExtraFields(Model $model, array $fields, string $glue = null): void
public function addExtraFields(Model $model, array $fields, ?string $glue = null): void
{
// display extra field in line
if ($glue) {
Expand Down
4 changes: 2 additions & 2 deletions src/CardDeck.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ protected function addPaginator(): void
* @param array<int, string>|null $fields
*/
#[\Override]
public function setModel(Model $model, array $fields = null, array $extra = null): void
public function setModel(Model $model, ?array $fields = null, ?array $extra = null): void
{
parent::setModel($model);

Expand Down Expand Up @@ -246,7 +246,7 @@ protected function jsExecute($return, Model\UserAction $action): JsBlock
/**
* Override this method for setting notifier based on action or model value.
*/
protected function jsCreateNotifier(Model\UserAction $action, string $msg = null): JsBlock
protected function jsCreateNotifier(Model\UserAction $action, ?string $msg = null): JsBlock
{
$notifier = Factory::factory($this->notifyDefault);
if ($msg) {
Expand Down
2 changes: 1 addition & 1 deletion src/CardTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class CardTable extends Table
* @param array<int, string>|null $fields
*/
#[\Override]
public function setModel(Model $entity, array $fields = null): void
public function setModel(Model $entity, ?array $fields = null): void
{
if ($this->_bypass) {
parent::setModel($entity);
Expand Down
4 changes: 2 additions & 2 deletions src/Crud.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function applySort(): void
}

#[\Override]
public function setModel(Model $model, array $fields = null): void
public function setModel(Model $model, ?array $fields = null): void
{
$model->assertIsModel();

Expand Down Expand Up @@ -221,7 +221,7 @@ protected function getJsGridAction(Model\UserAction $action): ?JsExpressionable
/**
* Override this method for setting notifier based on action or model value.
*/
protected function jsCreateNotifier(string $msg = null): JsExpressionable
protected function jsCreateNotifier(?string $msg = null): JsExpressionable
{
$notifier = Factory::factory($this->notifyDefault);
if ($msg) {
Expand Down
9 changes: 3 additions & 6 deletions src/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,9 @@ protected function initLayout(): void
/**
* Setter for control display rules.
*
* @param array $rules
*
* @return $this
*/
public function setControlsDisplayRules($rules = [])
public function setControlsDisplayRules(array $rules = [])
{
$this->controlDisplayRules = $rules;

Expand All @@ -170,12 +168,11 @@ public function setControlsDisplayRules($rules = [])
/**
* Set display rule for a group collection.
*
* @param array $rules
* @param string|View $selector
*
* @return $this
*/
public function setGroupDisplayRules($rules = [], $selector = '.atk-form-group')
public function setGroupDisplayRules(array $rules = [], $selector = '.atk-form-group')
{
if (is_object($selector)) {
$selector = '#' . $selector->getHtmlId();
Expand All @@ -191,7 +188,7 @@ public function setGroupDisplayRules($rules = [], $selector = '.atk-form-group')
* @param array<int, string>|null $fields if null, then all "editable" fields will be added
*/
#[\Override]
public function setModel(Model $entity, array $fields = null): void
public function setModel(Model $entity, ?array $fields = null): void
{
$entity->assertIsEntity();

Expand Down
2 changes: 1 addition & 1 deletion src/Form/AbstractLayout.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ protected function getModelFields(Model $model)
* @param array<int, string>|null $fields
*/
#[\Override]
public function setModel(Model $entity, array $fields = null): void
public function setModel(Model $entity, ?array $fields = null): void
{
$entity->assertIsEntity();

Expand Down
4 changes: 2 additions & 2 deletions src/Form/Control/Multiline.php
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ private function getMlRowId(array $row): ?string
* @param array<int, string>|null $fields
*/
#[\Override]
public function setModel(Model $model, array $fields = null): void
public function setModel(Model $model, ?array $fields = null): void
{
parent::setModel($model);

Expand All @@ -427,7 +427,7 @@ public function setModel(Model $model, array $fields = null): void
* Otherwise, form will try to save 'multiline' field value as an array when form is save.
* $multiline = $form->addControl('multiline', [Multiline::class], ['neverPersist' => true])
*/
public function setReferenceModel(string $refModelName, Model $entity = null, array $fieldNames = []): void
public function setReferenceModel(string $refModelName, ?Model $entity = null, array $fieldNames = []): void
{
if ($entity === null) {
if (!$this->form->model->isEntity()) {
Expand Down
2 changes: 1 addition & 1 deletion src/Form/Control/ScopeBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ protected function addReferenceRules(Field $field): void
}
}

protected function getRule(string $type, array $defaults = [], Field $field = null): array
protected function getRule(string $type, array $defaults = [], ?Field $field = null): array
{
$rule = static::$ruleTypes[$type] ?? static::$ruleTypes['default'];

Expand Down
2 changes: 1 addition & 1 deletion src/Form/Layout/Columns.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Columns extends Form\Layout
public $size = '';

#[\Override]
public function setModel(Model $entity, array $fields = null): void
public function setModel(Model $entity, ?array $fields = null): void
{
// dont add any fields automatically
parent::setModel($entity, []);
Expand Down
2 changes: 1 addition & 1 deletion src/Form/Layout/Section/Accordion.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ protected function init(): void
* @return Form\Layout
*/
#[\Override]
public function addSection($title, \Closure $callback = null, $icon = 'dropdown')
public function addSection($title, ?\Closure $callback = null, $icon = 'dropdown')
{
$section = parent::addSection($title, $callback, $icon);

Expand Down
2 changes: 1 addition & 1 deletion src/Form/Layout/Section/Tabs.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Tabs extends UiTabs
* @return Form\Layout
*/
#[\Override]
public function addTab($name, \Closure $callback = null, array $settings = [])
public function addTab($name, ?\Closure $callback = null, array $settings = [])
{
$tab = parent::addTab($name, $callback, $settings);

Expand Down
18 changes: 9 additions & 9 deletions src/Grid.php
Original file line number Diff line number Diff line change
Expand Up @@ -345,9 +345,9 @@ public function jsReload($args = [], $afterSuccess = null, array $apiConfig = []
* Adds a new button into the action column on the right. For Crud this
* column will already contain "delete" and "edit" buttons.
*
* @param string|array|View $button Label text, object or seed for the Button
* @param string|array|View $button Label text, object or seed for the Button
* @param JsExpressionable|JsCallbackSetClosure $action
* @param bool|\Closure<T of Model>(T): bool $isDisabled
* @param bool|\Closure<T of Model>(T): bool $isDisabled
*
* @return View
*/
Expand All @@ -361,7 +361,7 @@ public function addActionButton($button, $action = null, string $confirmMsg = ''
*
* @return View
*/
public function addExecutorButton(ExecutorInterface $executor, Button $button = null)
public function addExecutorButton(ExecutorInterface $executor, ?Button $button = null)
{
if ($button !== null) {
$this->add($button);
Expand Down Expand Up @@ -395,7 +395,7 @@ private function getActionButtons(): Table\Column\ActionButtons
*
* @param View|string $view
* @param JsExpressionable|JsCallbackSetClosure $action
* @param bool|\Closure<T of Model>(T): bool $isDisabled
* @param bool|\Closure<T of Model>(T): bool $isDisabled
*
* @return View
*/
Expand Down Expand Up @@ -496,10 +496,10 @@ public function addPopup($columnName, $popup = null, $icon = 'caret square down'
* Similar to addActionButton but when button is clicked, modal is displayed
* with the $title and $callback is executed.
*
* @param string|array|View $button
* @param string $title
* @param \Closure(View, mixed): void $callback
* @param array $args extra URL argument for callback
* @param string|array|View $button
* @param string $title
* @param \Closure(View, mixed): void $callback
* @param array $args extra URL argument for callback
* @param bool|\Closure<T of Model>(T): bool $isDisabled
*
* @return View
Expand Down Expand Up @@ -616,7 +616,7 @@ public function applySort(): void
* @param array<int, string>|null $fields if null, then all "editable" fields will be added
*/
#[\Override]
public function setModel(Model $model, array $fields = null): void
public function setModel(Model $model, ?array $fields = null): void
{
$this->table->setModel($model, $fields);

Expand Down
14 changes: 7 additions & 7 deletions src/HtmlTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ protected function emptyTagTree(TagTree $tagTree): void
* @param string|array<string, string> $tag
* @param ($tag is array ? never : string|null) $value
*/
protected function _setOrAppend($tag, string $value = null, bool $encodeHtml = true, bool $append = false, bool $throwIfNotFound = true): void
protected function _setOrAppend($tag, ?string $value = null, bool $encodeHtml = true, bool $append = false, bool $throwIfNotFound = true): void
{
// $tag passed as associative array [tag => value]
if (is_array($tag) && $value === null) { // @phpstan-ignore-line
Expand Down Expand Up @@ -196,7 +196,7 @@ protected function _setOrAppend($tag, string $value = null, bool $encodeHtml = t
*
* @return $this
*/
public function set($tag, string $value = null): self
public function set($tag, ?string $value = null): self
{
$this->_setOrAppend($tag, $value, true, false);

Expand All @@ -212,7 +212,7 @@ public function set($tag, string $value = null): self
*
* @return $this
*/
public function trySet($tag, string $value = null): self
public function trySet($tag, ?string $value = null): self
{
$this->_setOrAppend($tag, $value, true, false, false);

Expand All @@ -228,7 +228,7 @@ public function trySet($tag, string $value = null): self
*
* @return $this
*/
public function dangerouslySetHtml($tag, string $value = null): self
public function dangerouslySetHtml($tag, ?string $value = null): self
{
$this->_setOrAppend($tag, $value, false, false);

Expand All @@ -244,7 +244,7 @@ public function dangerouslySetHtml($tag, string $value = null): self
*
* @return $this
*/
public function tryDangerouslySetHtml($tag, string $value = null): self
public function tryDangerouslySetHtml($tag, ?string $value = null): self
{
$this->_setOrAppend($tag, $value, false, false, false);

Expand Down Expand Up @@ -427,7 +427,7 @@ public function loadFromString(string $str, bool $allowParseCache = false): self
return $this;
}

protected function parseTemplateTree(array &$inputReversed, string $openedTag = null): TagTree
protected function parseTemplateTree(array &$inputReversed, ?string $openedTag = null): TagTree
{
$tagTree = new TagTree($this, $openedTag ?? self::TOP_TAG);

Expand Down Expand Up @@ -538,7 +538,7 @@ public function toLoadableString(string $region = self::TOP_TAG): string
return implode('', $res);
}

public function renderToHtml(string $region = null): string
public function renderToHtml(?string $region = null): string
{
return $this->renderTagTreeToHtml($this->getTagTree($region ?? self::TOP_TAG));
}
Expand Down
Loading

0 comments on commit 5fc79ed

Please sign in to comment.