From 2538bfe7572331e63284c8fa1a2403ffcc6de287 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Muhammed=20Said=20=C3=87ak=C4=B1r?=
 <muhammedsaidckr@gmail.com>
Date: Fri, 1 Dec 2023 02:52:39 +0300
Subject: [PATCH] Refactored the url parse process in the DSN parse method.

By calling parse_url just once, eliminating the unnecessary calls
---
 pkg/dsn/Dsn.php | 19 +++++--------------
 1 file changed, 5 insertions(+), 14 deletions(-)

diff --git a/pkg/dsn/Dsn.php b/pkg/dsn/Dsn.php
index a5cc139b2..d01ad1961 100644
--- a/pkg/dsn/Dsn.php
+++ b/pkg/dsn/Dsn.php
@@ -215,23 +215,14 @@ public static function parse(string $dsn): array
         unset($schemeParts[0]);
         $schemeExtensions = array_values($schemeParts);
 
-        $user = parse_url($dsn, PHP_URL_USER) ?: null;
-        if (is_string($user)) {
-            $user = rawurldecode($user);
-        }
-
-        $password = parse_url($dsn, PHP_URL_PASS) ?: null;
-        if (is_string($password)) {
-            $password = rawurldecode($password);
-        }
+        $parsedDsn = parse_url($dsn);
 
-        $path = parse_url($dsn, PHP_URL_PATH) ?: null;
-        if ($path) {
-            $path = rawurldecode($path);
-        }
+        $user = isset($parsedDsn['user']) ? rawurldecode($parsedDsn['user']) : null;
+        $password = isset($parsedDsn['pass']) ? rawurldecode($parsedDsn['pass']) : null;
+        $path = isset($parsedDsn['path']) ? rawurldecode($parsedDsn['path']) : null;
 
         $query = [];
-        $queryString = parse_url($dsn, PHP_URL_QUERY) ?: null;
+        $queryString = $parsedDsn['query'] ?? null;
         if (is_string($queryString)) {
             $query = self::httpParseQuery($queryString, '&', PHP_QUERY_RFC3986);
         }