Apply suggestions from code review
authorMarcel Werk <burntime@woltlab.com>
Thu, 19 Sep 2024 13:37:09 +0000 (15:37 +0200)
committerMarcel Werk <burntime@woltlab.com>
Tue, 12 Nov 2024 11:51:53 +0000 (12:51 +0100)
wcfsetup/install/files/lib/acp/page/UserRankListPage.class.php
wcfsetup/install/files/lib/page/AbstractGridViewPage.class.php

index c6368082546e3bcaf67e240452850611653b8a43..a487e7e0f269742eeecf138ffe189164247dbd1d 100644 (file)
@@ -3,6 +3,7 @@
 namespace wcf\acp\page;
 
 use wcf\page\AbstractGridViewPage;
+use wcf\system\view\grid\AbstractGridView;
 use wcf\system\view\grid\UserRankGridView;
 
 /**
@@ -31,8 +32,9 @@ class UserRankListPage extends AbstractGridViewPage
      */
     public $neededModules = ['MODULE_USER_RANK'];
 
-    /**
-     * @inheritDoc
-     */
-    protected string $gridViewClassName = UserRankGridView::class;
+    #[\Override]
+    protected function createGridViewController(): AbstractGridView
+    {
+        return new UserRankGridView();
+    }
 }
index 06b279f5b1934a33191b50994e78c236fd99f453..78dbb60b4dd5eca2e258fd213622d89497882f81 100644 (file)
@@ -2,15 +2,12 @@
 
 namespace wcf\page;
 
-use wcf\system\exception\ParentClassException;
-use wcf\system\exception\SystemException;
 use wcf\system\request\LinkHandler;
 use wcf\system\view\grid\AbstractGridView;
 use wcf\system\WCF;
 
 abstract class AbstractGridViewPage extends AbstractPage
 {
-    protected string $gridViewClassName;
     protected AbstractGridView $gridView;
     protected int $pageNo = 1;
     protected string $sortField = '';
@@ -52,15 +49,7 @@ abstract class AbstractGridViewPage extends AbstractPage
 
     protected function initGridView(): void
     {
-        if (!isset($this->gridViewClassName)) {
-            throw new SystemException('Grid view class name not specified.');
-        }
-
-        if (!\is_subclass_of($this->gridViewClassName, AbstractGridView::class)) {
-            throw new ParentClassException($this->gridViewClassName, AbstractGridView::class);
-        }
-
-        $this->gridView = new $this->gridViewClassName;
+        $this->gridView = $this->createGridViewController();
 
         if ($this->sortField) {
             $this->gridView->setSortField($this->sortField);
@@ -69,4 +58,6 @@ abstract class AbstractGridViewPage extends AbstractPage
         $this->gridView->setPageNo($this->pageNo);
         $this->gridView->setBaseUrl(LinkHandler::getInstance()->getControllerLink(static::class));
     }
+
+    protected abstract function createGridViewController(): AbstractGridView;
 }