From 81e988aac87f4e2e58694f6760ccb04ab0d53879 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Thu, 25 May 2023 15:40:16 -0300 Subject: [PATCH] Inline Triggers::main() into the Triggers\IndexController MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The main() method is handling the request/response, so it's better to move this code to the controller. Signed-off-by: MaurĂ­cio Meneghini Fauth --- .../Controllers/Triggers/IndexController.php | 27 ++++++++++++- libraries/classes/Triggers/Triggers.php | 38 +------------------ psalm-baseline.xml | 6 +-- .../Triggers/IndexControllerTest.php | 7 ++-- 4 files changed, 34 insertions(+), 44 deletions(-) diff --git a/libraries/classes/Controllers/Triggers/IndexController.php b/libraries/classes/Controllers/Triggers/IndexController.php index c6bc2a8de1..2374fd3c02 100644 --- a/libraries/classes/Controllers/Triggers/IndexController.php +++ b/libraries/classes/Controllers/Triggers/IndexController.php @@ -73,6 +73,31 @@ final class IndexController extends AbstractController */ $GLOBALS['errors'] = []; - $this->triggers->main(); + $this->triggers->handleEditor(); + $this->triggers->export(); + + $items = Triggers::getDetails($this->dbi, $GLOBALS['db'], $GLOBALS['table']); + $hasTriggerPrivilege = Util::currentUserHasPrivilege('TRIGGER', $GLOBALS['db'], $GLOBALS['table']); + $isAjax = $this->response->isAjax() && empty($_REQUEST['ajax_page_request']); + + $rows = ''; + foreach ($items as $item) { + $rows .= $this->template->render('triggers/row', [ + 'db' => $GLOBALS['db'], + 'table' => $GLOBALS['table'], + 'trigger' => $item, + 'has_drop_privilege' => $hasTriggerPrivilege, + 'has_edit_privilege' => $hasTriggerPrivilege, + 'row_class' => $isAjax ? 'ajaxInsert hide' : '', + ]); + } + + $this->render('triggers/list', [ + 'db' => $GLOBALS['db'], + 'table' => $GLOBALS['table'], + 'items' => $items, + 'rows' => $rows, + 'has_privilege' => $hasTriggerPrivilege, + ]); } } diff --git a/libraries/classes/Triggers/Triggers.php b/libraries/classes/Triggers/Triggers.php index 6a315330cb..fb1ab58702 100644 --- a/libraries/classes/Triggers/Triggers.php +++ b/libraries/classes/Triggers/Triggers.php @@ -44,42 +44,6 @@ class Triggers ) { } - /** - * Main function for the triggers functionality - */ - public function main(): void - { - /** - * Process all requests - */ - $this->handleEditor(); - $this->export(); - - $items = self::getDetails($this->dbi, $GLOBALS['db'], $GLOBALS['table']); - $hasTriggerPrivilege = Util::currentUserHasPrivilege('TRIGGER', $GLOBALS['db'], $GLOBALS['table']); - $isAjax = $this->response->isAjax() && empty($_REQUEST['ajax_page_request']); - - $rows = ''; - foreach ($items as $item) { - $rows .= $this->template->render('triggers/row', [ - 'db' => $GLOBALS['db'], - 'table' => $GLOBALS['table'], - 'trigger' => $item, - 'has_drop_privilege' => $hasTriggerPrivilege, - 'has_edit_privilege' => $hasTriggerPrivilege, - 'row_class' => $isAjax ? 'ajaxInsert hide' : '', - ]); - } - - echo $this->template->render('triggers/list', [ - 'db' => $GLOBALS['db'], - 'table' => $GLOBALS['table'], - 'items' => $items, - 'rows' => $rows, - 'has_privilege' => $hasTriggerPrivilege, - ]); - } - /** * Handles editor requests for adding or editing an item */ @@ -469,7 +433,7 @@ class Triggers echo $message->getDisplay(); } - private function export(): void + public function export(): void { if (empty($_GET['export_item']) || empty($_GET['item_name'])) { return; diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 270ff0f8a4..d089ffdc52 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -4311,10 +4311,11 @@ + $item - + $request - + @@ -12943,7 +12944,6 @@ $createItem $exportData - $item diff --git a/test/classes/Controllers/Triggers/IndexControllerTest.php b/test/classes/Controllers/Triggers/IndexControllerTest.php index b6317c981d..12ad7c9c64 100644 --- a/test/classes/Controllers/Triggers/IndexControllerTest.php +++ b/test/classes/Controllers/Triggers/IndexControllerTest.php @@ -78,13 +78,14 @@ class IndexControllerTest extends AbstractTestCase 'has_edit_privilege' => true, 'row_class' => '', ]); - - $this->expectOutputString($template->render('triggers/list', [ + $expected = $template->render('triggers/list', [ 'db' => $GLOBALS['db'], 'table' => $GLOBALS['table'], 'items' => $items, 'rows' => $rows, 'has_privilege' => true, - ])); + ]); + + $this->assertSame($expected, $response->getHTMLResult()); } }