Skip to content

Commit

Permalink
Specify button renderer callable type (#143)
Browse files Browse the repository at this point in the history
  • Loading branch information
vjik authored Dec 5, 2023
1 parent 3495a4b commit 601909c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/Column/ActionColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* the items.
*
* @psalm-type UrlCreator = callable(string,DataContext):string
* @psalm-type ButtonRenderer = callable(string):string
*/
final class ActionColumn implements ColumnInterface
{
Expand All @@ -25,7 +26,7 @@ final class ActionColumn implements ColumnInterface
* @param ?callable $urlCreator A callback that creates a button URL using the specified data information.
*
* @psalm-param UrlCreator|null $urlCreator
* @psalm-param array<string,Closure> $buttons
* @psalm-param array<string,ButtonRenderer> $buttons
* @psalm-param array<string,bool|Closure>|null $visibleButtons
*/
public function __construct(
Expand Down
8 changes: 4 additions & 4 deletions src/Column/ActionColumnRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Yiisoft\Yii\DataView\Column;

use Closure;
use InvalidArgumentException;
use LogicException;
use Yiisoft\Html\Html;
Expand All @@ -14,6 +13,7 @@

/**
* @psalm-import-type UrlCreator from ActionColumn
* @psalm-import-type ButtonRenderer from ActionColumn
*/
final class ActionColumnRenderer implements ColumnRendererInterface
{
Expand All @@ -23,13 +23,13 @@ final class ActionColumnRenderer implements ColumnRendererInterface
private $defaultUrlCreator;

/**
* @psalm-var array<string,Closure>
* @psalm-var array<string,ButtonRenderer>
*/
private readonly array $defaultButtons;

/**
* @psalm-param UrlCreator|null $defaultUrlCreator
* @psalm-param array<string,Closure> $defaultButtons
* @psalm-param array<string,ButtonRenderer>|null $defaultButtons
*/
public function __construct(
?callable $defaultUrlCreator = null,
Expand Down Expand Up @@ -117,7 +117,7 @@ function (array $matches) use ($column, $buttons, $context): string {
isset($buttons[$name])
) {
$url = $this->createUrl($name, $context);
return (string)$buttons[$name]($url);
return $buttons[$name]($url);
}

return '';
Expand Down

0 comments on commit 601909c

Please sign in to comment.