From 93109f2ee0bd162db7adf17954a2e7532cd69ec4 Mon Sep 17 00:00:00 2001
From: Oliver Bartsch <bo@cedev.de>
Date: Sat, 22 Feb 2020 14:01:07 +0100
Subject: [PATCH] [TASK] Harden types in ext:dashboard

* Add some missing return types
* Remove wrong return type annotation
* Add missing import
* Use strict mode for `in_array`

Resolves: #90487
Releases: master
Change-Id: Iaadf0a1b38f743ac3777d5b3600584aa9fc957e7
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/63369
Tested-by: Richard Haeser <richard@maxserv.com>
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Daniel Goerz <daniel.goerz@posteo.de>
Reviewed-by: Richard Haeser <richard@maxserv.com>
Reviewed-by: Daniel Goerz <daniel.goerz@posteo.de>
---
 typo3/sysext/dashboard/Classes/Dashboard.php                 | 2 --
 typo3/sysext/dashboard/Classes/DashboardRepository.php       | 5 +++--
 .../Classes/DependencyInjection/DashboardWidgetPass.php      | 2 +-
 typo3/sysext/dashboard/Classes/WidgetRegistry.php            | 2 +-
 4 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/typo3/sysext/dashboard/Classes/Dashboard.php b/typo3/sysext/dashboard/Classes/Dashboard.php
index 8199927931ec..be57b5f8e622 100644
--- a/typo3/sysext/dashboard/Classes/Dashboard.php
+++ b/typo3/sysext/dashboard/Classes/Dashboard.php
@@ -100,8 +100,6 @@ class Dashboard
     /**
      * This will return a list of all widgets of the current dashboard object. It will only include available
      * widgets and will add the initialised object of the widget itself
-     *
-     * @return array
      */
     public function initializeWidgets(): void
     {
diff --git a/typo3/sysext/dashboard/Classes/DashboardRepository.php b/typo3/sysext/dashboard/Classes/DashboardRepository.php
index a217bc0c29d1..72cf1d58417c 100644
--- a/typo3/sysext/dashboard/Classes/DashboardRepository.php
+++ b/typo3/sysext/dashboard/Classes/DashboardRepository.php
@@ -20,6 +20,7 @@ use Psr\Container\ContainerInterface;
 use TYPO3\CMS\Core\Database\ConnectionPool;
 use TYPO3\CMS\Core\Database\Query\QueryBuilder;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Dashboard\Widgets\Interfaces\WidgetInterface;
 
 class DashboardRepository
 {
@@ -78,7 +79,7 @@ class DashboardRepository
         return $results;
     }
 
-    public function create(DashboardPreset $dashboardPreset, int $userId, string $title = '')
+    public function create(DashboardPreset $dashboardPreset, int $userId, string $title = ''): ?Dashboard
     {
         $widgets = [];
         $title = $title ?: $dashboardPreset->getTitle();
@@ -139,7 +140,7 @@ class DashboardRepository
     {
         $allowedFields = [];
         foreach ($values as $field => $value) {
-            if (!empty($value) && in_array($field, $this->allowedFields)) {
+            if (!empty($value) && in_array((string)$field, $this->allowedFields, true)) {
                 $allowedFields[$field] = $value;
             }
         }
diff --git a/typo3/sysext/dashboard/Classes/DependencyInjection/DashboardWidgetPass.php b/typo3/sysext/dashboard/Classes/DependencyInjection/DashboardWidgetPass.php
index 0ae86bec2190..4a3a63cd8d38 100644
--- a/typo3/sysext/dashboard/Classes/DependencyInjection/DashboardWidgetPass.php
+++ b/typo3/sysext/dashboard/Classes/DependencyInjection/DashboardWidgetPass.php
@@ -41,7 +41,7 @@ final class DashboardWidgetPass implements CompilerPassInterface
     /**
      * @param ContainerBuilder $container
      */
-    public function process(ContainerBuilder $container)
+    public function process(ContainerBuilder $container): void
     {
         $widgetRegistryDefinition = $container->findDefinition(WidgetRegistry::class);
         if (!$widgetRegistryDefinition) {
diff --git a/typo3/sysext/dashboard/Classes/WidgetRegistry.php b/typo3/sysext/dashboard/Classes/WidgetRegistry.php
index fe817b5ce40f..f5cd73138292 100644
--- a/typo3/sysext/dashboard/Classes/WidgetRegistry.php
+++ b/typo3/sysext/dashboard/Classes/WidgetRegistry.php
@@ -80,7 +80,7 @@ class WidgetRegistry implements SingletonInterface
         return $GLOBALS['BE_USER'];
     }
 
-    public function widgetItemsProcFunc(array $parameters)
+    public function widgetItemsProcFunc(array $parameters): void
     {
         foreach ($this->widgets as $identifier => $widget) {
             $widgetObject = $this->container->get($widget);
-- 
GitLab