From 46bccd1bf4fac9ed1fb6e14ea576ee7df53dd318 Mon Sep 17 00:00:00 2001
From: Helmut Hummel <typo3@helhum.io>
Date: Thu, 16 Dec 2021 16:03:26 +0100
Subject: [PATCH] [BUGFIX] Fix PHP 8 strict warning in Package MetaData
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

A "type" does not need to be set in a composer.json,
so the checks for package type must account for the type
being null, to not trigger a warning in PHP 8

Releases: 11.5, main
Resolves: #96372
Change-Id: Ic607c3dbb16dfcf4a28b0417b8340be36bcafa87
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/72695
Tested-by: Markus Klein <markus.klein@typo3.org>
Tested-by: core-ci <typo3@b13.com>
Tested-by: Simon Gilli <typo3@gilbertsoft.org>
Tested-by: Stefan Bürk <stefan@buerk.tech>
Tested-by: Helmut Hummel <typo3@helhum.io>
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Reviewed-by: Simon Gilli <typo3@gilbertsoft.org>
Reviewed-by: Stefan Bürk <stefan@buerk.tech>
Reviewed-by: Helmut Hummel <typo3@helhum.io>
---
 .../sysext/core/Classes/Package/MetaData.php  | 14 ++--
 .../core/Tests/Unit/Package/MetaDataTest.php  | 66 +++++++++++++++++++
 2 files changed, 73 insertions(+), 7 deletions(-)
 create mode 100644 typo3/sysext/core/Tests/Unit/Package/MetaDataTest.php

diff --git a/typo3/sysext/core/Classes/Package/MetaData.php b/typo3/sysext/core/Classes/Package/MetaData.php
index 9cbe90a1cd07..f34a79f68a48 100644
--- a/typo3/sysext/core/Classes/Package/MetaData.php
+++ b/typo3/sysext/core/Classes/Package/MetaData.php
@@ -40,7 +40,7 @@ class MetaData
     /**
      * Package type
      *
-     * @var string
+     * @var string|null
      */
     protected $packageType;
 
@@ -52,13 +52,13 @@ class MetaData
 
     /**
      * Package title
-     * @var ?string
+     * @var string|null
      */
     protected $title;
 
     /**
      * Package description
-     * @var string
+     * @var string|null
      */
     protected $description;
 
@@ -98,7 +98,7 @@ class MetaData
 
     public function isExtensionType(): bool
     {
-        return str_starts_with($this->packageType, 'typo3-cms-');
+        return is_string($this->packageType) && str_starts_with($this->packageType, 'typo3-cms-');
     }
 
     public function isFrameworkType(): bool
@@ -119,7 +119,7 @@ class MetaData
     /**
      * Set package type
      *
-     * @param string $packageType
+     * @param string|null $packageType
      */
     public function setPackageType($packageType)
     {
@@ -153,7 +153,7 @@ class MetaData
     }
 
     /**
-     * @return string The package description
+     * @return string|null The package description
      */
     public function getDescription()
     {
@@ -161,7 +161,7 @@ class MetaData
     }
 
     /**
-     * @param string $description The package description to set
+     * @param string|null $description The package description to set
      */
     public function setDescription($description)
     {
diff --git a/typo3/sysext/core/Tests/Unit/Package/MetaDataTest.php b/typo3/sysext/core/Tests/Unit/Package/MetaDataTest.php
new file mode 100644
index 000000000000..67a3f119b367
--- /dev/null
+++ b/typo3/sysext/core/Tests/Unit/Package/MetaDataTest.php
@@ -0,0 +1,66 @@
+<?php
+
+declare(strict_types=1);
+
+/*
+ * This file is part of the TYPO3 CMS project.
+ *
+ * It is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, either version 2
+ * of the License, or any later version.
+ *
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
+ *
+ * The TYPO3 project - inspiring people to share!
+ */
+
+namespace TYPO3\CMS\Core\Tests\Unit\Package;
+
+use TYPO3\CMS\Core\Package\MetaData;
+use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
+
+class MetaDataTest extends UnitTestCase
+{
+    public function typeIsCorrectlyResolvedDataProvider(): \Generator
+    {
+        yield 'framework type is set' => [
+            'typo3-cms-framework',
+            true,
+            true,
+        ];
+
+        yield 'extension type is set' => [
+            'typo3-cms-extension',
+            true,
+            false,
+        ];
+
+        yield 'no type is set' => [
+            null,
+            false,
+            false,
+        ];
+
+        yield 'other type is set' => [
+            'other',
+            false,
+            false,
+        ];
+    }
+
+    /**
+     * @param ?string $type
+     * @param bool $isExtension
+     * @param bool $isFramework
+     * @test
+     * @dataProvider typeIsCorrectlyResolvedDataProvider
+     */
+    public function typeIsCorrectlyResolved(?string $type, bool $isExtension, bool $isFramework): void
+    {
+        $metaData = new MetaData('foo');
+        $metaData->setPackageType($type);
+        self::assertSame($isExtension, $metaData->isExtensionType());
+        self::assertSame($isFramework, $metaData->isFrameworkType());
+    }
+}
-- 
GitLab