From b2580655751416b41318f14370394d137fd0a247 Mon Sep 17 00:00:00 2001
From: Daniel Siepmann <coding@daniel-siepmann.de>
Date: Mon, 3 Feb 2025 12:30:55 +0100
Subject: [PATCH] [TASK] Raise PHP Language Level to 8.1

Resolves: #1568
---
 .../Controller/FrontEndEditorController.php   | 25 ++++++-------------
 Classes/Controller/TeaController.php          |  9 +++----
 Classes/Domain/Model/Tea.php                  | 12 +++------
 rector.php                                    |  2 +-
 4 files changed, 15 insertions(+), 33 deletions(-)

diff --git a/Classes/Controller/FrontEndEditorController.php b/Classes/Controller/FrontEndEditorController.php
index 8b2c50c..486c5c7 100644
--- a/Classes/Controller/FrontEndEditorController.php
+++ b/Classes/Controller/FrontEndEditorController.php
@@ -17,15 +17,10 @@ use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
  */
 class FrontEndEditorController extends ActionController
 {
-    private Context $context;
-
-    private TeaRepository $teaRepository;
-
-    public function __construct(Context $context, TeaRepository $teaRepository)
-    {
-        $this->context = $context;
-        $this->teaRepository = $teaRepository;
-    }
+    public function __construct(
+        private readonly Context $context,
+        private readonly TeaRepository $teaRepository,
+    ) {}
 
     public function indexAction(): ResponseInterface
     {
@@ -48,9 +43,7 @@ class FrontEndEditorController extends ActionController
         return $userUid;
     }
 
-    /**
-     * @Extbase\IgnoreValidation("tea")
-     */
+    #[Extbase\IgnoreValidation(['argumentName' => 'tea'])]
     public function editAction(Tea $tea): ResponseInterface
     {
         $this->checkIfUserIsOwner($tea);
@@ -79,9 +72,7 @@ class FrontEndEditorController extends ActionController
         return $this->redirect('index');
     }
 
-    /**
-     * @Extbase\IgnoreValidation("tea")
-     */
+    #[Extbase\IgnoreValidation(['argumentName' => 'tea'])]
     public function newAction(?Tea $tea = null): ResponseInterface
     {
         // Note: We are using `makeInstance` here instead of `new` to allow for XCLASSing.
@@ -100,9 +91,7 @@ class FrontEndEditorController extends ActionController
         return $this->redirect('index');
     }
 
-    /**
-     * @Extbase\IgnoreValidation("tea")
-     */
+    #[Extbase\IgnoreValidation(['argumentName' => 'tea'])]
     public function deleteAction(Tea $tea): ResponseInterface
     {
         $this->checkIfUserIsOwner($tea);
diff --git a/Classes/Controller/TeaController.php b/Classes/Controller/TeaController.php
index 46086ac..4a715d6 100644
--- a/Classes/Controller/TeaController.php
+++ b/Classes/Controller/TeaController.php
@@ -14,12 +14,9 @@ use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
  */
 class TeaController extends ActionController
 {
-    private TeaRepository $teaRepository;
-
-    public function __construct(TeaRepository $teaRepository)
-    {
-        $this->teaRepository = $teaRepository;
-    }
+    public function __construct(
+        private readonly TeaRepository $teaRepository,
+    ) {}
 
     public function indexAction(): ResponseInterface
     {
diff --git a/Classes/Domain/Model/Tea.php b/Classes/Domain/Model/Tea.php
index 7ce31a0..c7f4a32 100644
--- a/Classes/Domain/Model/Tea.php
+++ b/Classes/Domain/Model/Tea.php
@@ -14,22 +14,18 @@ use TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy;
  */
 class Tea extends AbstractEntity
 {
-    /**
-     * @Extbase\Validate("StringLength", options={"maximum": 255})
-     * @Extbase\Validate("NotEmpty")
-     */
+    #[Extbase\Validate(['validator' => 'StringLength', 'options' => ['maximum' => 255]])]
+    #[Extbase\Validate(['validator' => 'NotEmpty'])]
     protected string $title = '';
 
-    /**
-     * @Extbase\Validate("StringLength", options={"maximum": 2000})
-     */
+    #[Extbase\Validate(['validator' => 'StringLength', 'options' => ['maximum' => 2000]])]
     protected string $description = '';
 
     /**
      * @var FileReference|null
      * @phpstan-var FileReference|LazyLoadingProxy|null
-     * @Extbase\ORM\Lazy
      */
+    #[Extbase\ORM\Lazy]
     protected $image;
 
     // Note: We cannot use `@var` for the more specific type annotation here as this confuses the Extbase type mapper.
diff --git a/rector.php b/rector.php
index 7f171a9..e8f7fdd 100644
--- a/rector.php
+++ b/rector.php
@@ -26,7 +26,7 @@ return RectorConfig::configure()
         __DIR__ . '/ext_emconf.php',
         __DIR__ . '/ext_localconf.php',
     ])
-    ->withPhpVersion(PhpVersion::PHP_74)
+    ->withPhpVersion(PhpVersion::PHP_81)
     ->withPhpSets(
         true
     )