From 8748f35604c2a261a58b96bbdad5191b754cec29 Mon Sep 17 00:00:00 2001 From: David GABISON Date: Mon, 18 Dec 2023 13:21:02 +0100 Subject: [PATCH] refactor: use container dependency injection following @kjohnson instructions --- src/Donations/Endpoints/ListDonations.php | 25 +++++++++++------------ 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/src/Donations/Endpoints/ListDonations.php b/src/Donations/Endpoints/ListDonations.php index f287e08f72..d74ed43ba4 100644 --- a/src/Donations/Endpoints/ListDonations.php +++ b/src/Donations/Endpoints/ListDonations.php @@ -12,6 +12,9 @@ use WP_REST_Request; use WP_REST_Response; +/** + * @unreleased The class is extendable + */ class ListDonations extends Endpoint { /** @@ -29,6 +32,15 @@ class ListDonations extends Endpoint */ protected $listTable; + /** + * @unreleased + * @access public + */ + public function __construct(DonationsListTable $listTable) + { + $this->listTable = $listTable; + } + /** * @inheritDoc */ @@ -119,7 +131,6 @@ public function registerRoute() } /** - * @unreleased Make the class extendable * @since 2.24.0 Change this to use the new ListTable class * @since 2.20.0 * @@ -130,7 +141,6 @@ public function registerRoute() */ public function handleRequest(WP_REST_Request $request): WP_REST_Response { - $this->init(); $this->request = $request; $donations = $this->getDonations(); @@ -153,16 +163,6 @@ public function handleRequest(WP_REST_Request $request): WP_REST_Response ); } - /** - * Initialize which list table to use. - * - * @unreleased - */ - protected function init () - { - $this->listTable = give(DonationsListTable::class); - } - /** * @since 2.24.0 Replace Query Builder with Donations model * @since 2.21.0 @@ -220,7 +220,6 @@ public function getTotalDonationsCount(): int } /** - * @unreleased Make the class extendable * @since 3.2.0 Updated query to account for possible null and empty values for _give_payment_mode meta * @since 2.24.0 Remove joins as it uses ModelQueryBuilder and change clauses to use attach_meta * @since 2.21.0