From 524013a8461071605b5b6dd193228ed2a39bf85e Mon Sep 17 00:00:00 2001 From: Kevin Papst Date: Thu, 21 Nov 2024 18:26:19 +0100 Subject: [PATCH] syntax updates for PHP 8.4 and strict phpstan rules --- src/DependencyInjection/TablerExtension.php | 2 +- src/Event/NotificationEvent.php | 2 +- src/Model/MenuItemModel.php | 2 +- src/Model/NotificationModel.php | 10 +++++----- src/Model/UserModel.php | 2 +- src/Twig/RuntimeExtension.php | 14 +++++++------- 6 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/DependencyInjection/TablerExtension.php b/src/DependencyInjection/TablerExtension.php index 552b8cd..c98c2b6 100644 --- a/src/DependencyInjection/TablerExtension.php +++ b/src/DependencyInjection/TablerExtension.php @@ -26,7 +26,7 @@ public function load(array $configs, ContainerBuilder $container): void $config = $this->processConfiguration($configuration, $configs); $options = $this->getContextOptions($config); - if (!empty($config)) { + if (count($options) > 0) { $container->setParameter('tabler_bundle.options', $options); } diff --git a/src/Event/NotificationEvent.php b/src/Event/NotificationEvent.php index 7e9372f..9012e2a 100644 --- a/src/Event/NotificationEvent.php +++ b/src/Event/NotificationEvent.php @@ -201,7 +201,7 @@ public function addNotification(NotificationV2Interface|NotificationInterface $n public function removeNotification(NotificationInterface $notification): void { - if (($key = array_search($notification, $this->notifications)) !== false) { + if (($key = array_search($notification, $this->notifications, true)) !== false) { unset($this->notifications[$key]); } } diff --git a/src/Model/MenuItemModel.php b/src/Model/MenuItemModel.php index 0760d67..46d8c01 100644 --- a/src/Model/MenuItemModel.php +++ b/src/Model/MenuItemModel.php @@ -148,7 +148,7 @@ public function addChild(MenuItemInterface $child): void public function removeChild(MenuItemInterface $child): void { - if (false !== ($key = array_search($child, $this->children))) { + if (false !== ($key = array_search($child, $this->children, true))) { unset($this->children[$key]); } } diff --git a/src/Model/NotificationModel.php b/src/Model/NotificationModel.php index 41b4ab4..af863ff 100644 --- a/src/Model/NotificationModel.php +++ b/src/Model/NotificationModel.php @@ -11,13 +11,13 @@ use KevinPapst\TablerBundle\Helper\Constants; -class NotificationModel implements NotificationV2Interface +class NotificationModel implements NotificationV2Interface // @phpstan-ignore class.implementsDeprecatedInterface { private ?string $url = null; - private bool $active = false; - private bool $disabled = false; - private bool $withBadge = true; - private bool $badgeAnimated = true; + private bool $active = false; + private bool $disabled = false; + private bool $withBadge = true; + private bool $badgeAnimated = true; private bool $html = false; diff --git a/src/Model/UserModel.php b/src/Model/UserModel.php index bd5d880..41cdb85 100644 --- a/src/Model/UserModel.php +++ b/src/Model/UserModel.php @@ -68,7 +68,7 @@ public function getIdentifier(): string public function getUserIdentifier(): string { - if (!empty($this->id)) { + if ($this->id !== '') { return $this->id; } diff --git a/src/Twig/RuntimeExtension.php b/src/Twig/RuntimeExtension.php index 35d3f97..bdc3667 100644 --- a/src/Twig/RuntimeExtension.php +++ b/src/Twig/RuntimeExtension.php @@ -25,10 +25,10 @@ final class RuntimeExtension implements RuntimeExtensionInterface * @param array $icons */ public function __construct( - private EventDispatcherInterface $eventDispatcher, - private ContextHelper $helper, - private array $routes, - private array $icons + private readonly EventDispatcherInterface $eventDispatcher, + private readonly ContextHelper $helper, + private readonly array $routes, + private readonly array $icons ) { } @@ -67,7 +67,7 @@ public function containerClass(string $class = ''): string $classList[] = 'container-fluid'; } - return trim(implode(' ', array_values($classList))); + return trim(implode(' ', $classList)); } /** @@ -115,12 +115,12 @@ public function getUserDetails(): ?UserDetailsEvent return $userEvent; } - public function createIcon(string $name, bool $withIconClass = false, string $default = null): string + public function createIcon(string $name, bool $withIconClass = false, ?string $default = null): string { return ''; } - public function icon(string $name, bool $withIconClass = false, string $default = null): string + public function icon(string $name, bool $withIconClass = false, ?string $default = null): string { return ($withIconClass ? 'icon ' : '') . ($this->icons[str_replace('-', '_', $name)] ?? ($default ?? $name)); }