From 7bd1d6795e3eef35f3ee6ef19c39fb132f197d60 Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Thu, 13 Jun 2024 10:19:33 +0900 Subject: [PATCH] Refactor error handling for SqlFileNotFoundException Moved the error handling for SqlFileNotFoundException into its own private method, handleSqlNotFound, for improved readability and simplicity. This change does not alter the functionality but enhances code structure and maintainability. --- src/RowInterfaceProvider.php | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/RowInterfaceProvider.php b/src/RowInterfaceProvider.php index 4eb3387..e0cd8cd 100644 --- a/src/RowInterfaceProvider.php +++ b/src/RowInterfaceProvider.php @@ -48,18 +48,23 @@ public function get(): QueryInterface // For development // @codeCoverageIgnoreStart } catch (SqlFileNotFoundException $e) { - try { - $named = $e->sql; - $instance = $this->injector->getInstance(RowInterface::class, $named); - error_log(sprintf('Warning: #[Sql(\'%s\')] is not vald. Change to #[\\Ray\\Di\\Di\\Named(\'%s\')]', $named, $named)); - - return $instance; - } catch (Unbound $unbound) { - throw $e; - } - // @codeCoverageIgnoreEnd + return $this->handleSqlNotFound($e); } return new SqlQueryRow($this->pdo, $sql); } + + private function handleSqlNotFound($e) + { + try { + $named = $e->sql; + $instance = $this->injector->getInstance(RowInterface::class, $named); + error_log(sprintf('Warning: #[Sql(\'%s\')] is not vald. Change to #[\\Ray\\Di\\Di\\Named(\'%s\')]', $named, $named)); + + return $instance; + } catch (Unbound $unbound) { + throw $e; + } + // @codeCoverageIgnoreEnd + } }