From a763bf1d8cdf208641b1fd52393317fd5becf32a Mon Sep 17 00:00:00 2001 From: Maarten Date: Wed, 27 Nov 2024 20:07:22 +0100 Subject: [PATCH] Refactor some if/else checks --- src/Http/View/Engine/HtmlEngine.php | 11 ++++------- src/Routing/RouteCollection.php | 1 + src/Routing/Router.php | 22 ---------------------- 3 files changed, 5 insertions(+), 29 deletions(-) delete mode 100644 src/Routing/Router.php diff --git a/src/Http/View/Engine/HtmlEngine.php b/src/Http/View/Engine/HtmlEngine.php index c094be6..887e125 100644 --- a/src/Http/View/Engine/HtmlEngine.php +++ b/src/Http/View/Engine/HtmlEngine.php @@ -15,14 +15,11 @@ class HtmlEngine extends Render $basePath = $_SERVER['DOCUMENT_ROOT']; $viewsPath = app()->resourcePath('views/' . str_replace('.', '/', $this->view) . '.php'); - if (file_exists($viewsPath)) { - extract($this->data); - - include $viewsPath; - - return; + if (!file_exists($viewsPath)) { + throw new \Exception('View not found'); } - throw new \Exception('View not found'); + extract($this->data); + include $viewsPath; } } \ No newline at end of file diff --git a/src/Routing/RouteCollection.php b/src/Routing/RouteCollection.php index 75a8fe4..4579091 100644 --- a/src/Routing/RouteCollection.php +++ b/src/Routing/RouteCollection.php @@ -71,6 +71,7 @@ class RouteCollection fn($key) => !is_numeric($key), ARRAY_FILTER_USE_KEY ); + return $route; } } diff --git a/src/Routing/Router.php b/src/Routing/Router.php deleted file mode 100644 index 6d90c2a..0000000 --- a/src/Routing/Router.php +++ /dev/null @@ -1,22 +0,0 @@ -