From 8835905a33f578541b2a4e3e8b39d6bd2f6657e1 Mon Sep 17 00:00:00 2001 From: Kevin Pfeifer Date: Sat, 29 Apr 2023 17:10:58 +0200 Subject: [PATCH] use finders with named arguments --- src/Controller/PanelsController.php | 4 ++-- src/Model/Table/PanelsTable.php | 14 ++++---------- src/Model/Table/RequestsTable.php | 3 +-- 3 files changed, 7 insertions(+), 14 deletions(-) diff --git a/src/Controller/PanelsController.php b/src/Controller/PanelsController.php index ef60b7bd0..18c14542f 100644 --- a/src/Controller/PanelsController.php +++ b/src/Controller/PanelsController.php @@ -63,7 +63,7 @@ public function beforeRender(EventInterface $event): void */ public function index(?string $requestId = null): void { - $query = $this->Panels->find('byRequest', ['requestId' => $requestId]); + $query = $this->Panels->find('byRequest', requestId: $requestId); $panels = $query->toArray(); if (empty($panels)) { throw new NotFoundException(); @@ -107,7 +107,7 @@ public function latestHistory(): ?Response throw new NotFoundException('No requests found'); } /** @var array{id:string}|null $historyPanel */ - $historyPanel = $this->Panels->find('byRequest', ['requestId' => $request['id']]) + $historyPanel = $this->Panels->find('byRequest', requestId: $request['id']) ->where(['title' => 'History']) ->select(['id']) ->first(); diff --git a/src/Model/Table/PanelsTable.php b/src/Model/Table/PanelsTable.php index ce0efced2..1326c4e24 100644 --- a/src/Model/Table/PanelsTable.php +++ b/src/Model/Table/PanelsTable.php @@ -16,7 +16,6 @@ use Cake\ORM\Query\SelectQuery; use Cake\ORM\Table; -use RuntimeException; /** * The panels table collects the information for each panel on @@ -49,20 +48,15 @@ public function initialize(array $config): void } /** - * Find panels by requestid + * Find panels by request id * * @param \Cake\ORM\Query\SelectQuery $query The query - * @param array $options The options to use. + * @param string|int $requestId The request id * @return \Cake\ORM\Query\SelectQuery The query. - * @throws \RuntimeException */ - public function findByRequest(SelectQuery $query, array $options): SelectQuery + public function findByRequest(SelectQuery $query, string|int $requestId): SelectQuery { - if (empty($options['requestId'])) { - throw new RuntimeException('Missing request id in findByRequest().'); - } - - return $query->where(['Panels.request_id' => $options['requestId']]) + return $query->where(['Panels.request_id' => $requestId]) ->orderBy(['Panels.title' => 'ASC']); } diff --git a/src/Model/Table/RequestsTable.php b/src/Model/Table/RequestsTable.php index 043d9a6a1..2c09a3dcd 100644 --- a/src/Model/Table/RequestsTable.php +++ b/src/Model/Table/RequestsTable.php @@ -71,10 +71,9 @@ public static function defaultConnectionName(): string * Finder method to get recent requests as a simple array * * @param \Cake\ORM\Query\SelectQuery $query The query - * @param array $options The options * @return \Cake\ORM\Query\SelectQuery The query. */ - public function findRecent(SelectQuery $query, array $options): SelectQuery + public function findRecent(SelectQuery $query): SelectQuery { return $query->orderBy(['Requests.requested_at' => 'DESC']) ->limit(10);