From 54b0441f5fb8263f9766c1bdcb88295b039446b3 Mon Sep 17 00:00:00 2001 From: kenjis Date: Sat, 22 Jun 2024 14:37:09 +0900 Subject: [PATCH 1/5] fix: if conditions to build DSN --- system/Database/OCI8/Connection.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/Database/OCI8/Connection.php b/system/Database/OCI8/Connection.php index be7eb37cb9a9..7acb3fd72dbc 100644 --- a/system/Database/OCI8/Connection.php +++ b/system/Database/OCI8/Connection.php @@ -120,7 +120,7 @@ private function isValidDSN(): bool */ public function connect(bool $persistent = false) { - if (empty($this->DSN) && ! $this->isValidDSN()) { + if ($this->DSN === null || $this->DSN === '' || ! $this->isValidDSN()) { $this->buildDSN(); } From 9a9da142629240e84d969f100c95952847ba089c Mon Sep 17 00:00:00 2001 From: kenjis Date: Sat, 22 Jun 2024 14:45:44 +0900 Subject: [PATCH 2/5] refactor: replace empty() --- phpstan-baseline.php | 2 +- system/Database/OCI8/Connection.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/phpstan-baseline.php b/phpstan-baseline.php index 91cb95cc0a44..2351c19b7c3e 100644 --- a/phpstan-baseline.php +++ b/phpstan-baseline.php @@ -3106,7 +3106,7 @@ $ignoreErrors[] = [ // identifier: empty.notAllowed 'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#', - 'count' => 5, + 'count' => 3, 'path' => __DIR__ . '/system/Database/OCI8/Connection.php', ]; $ignoreErrors[] = [ diff --git a/system/Database/OCI8/Connection.php b/system/Database/OCI8/Connection.php index 7acb3fd72dbc..86d2b349000e 100644 --- a/system/Database/OCI8/Connection.php +++ b/system/Database/OCI8/Connection.php @@ -126,7 +126,7 @@ public function connect(bool $persistent = false) $func = $persistent ? 'oci_pconnect' : 'oci_connect'; - return empty($this->charset) + return ($this->charset === '') ? $func($this->username, $this->password, $this->DSN) : $func($this->username, $this->password, $this->DSN, $this->charset); } From fa5f5c6051f21760b6853eca2af25b260ed3f687 Mon Sep 17 00:00:00 2001 From: kenjis Date: Sat, 22 Jun 2024 14:53:29 +0900 Subject: [PATCH 3/5] fix: Deprecated ctype_digit(): Argument of type int will be interpreted as string in the future --- system/Database/OCI8/Connection.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/Database/OCI8/Connection.php b/system/Database/OCI8/Connection.php index 86d2b349000e..da91f2cc20b0 100644 --- a/system/Database/OCI8/Connection.php +++ b/system/Database/OCI8/Connection.php @@ -632,7 +632,7 @@ protected function buildDSN() } $isEasyConnectableHostName = $this->hostname !== '' && ! str_contains($this->hostname, '/') && ! str_contains($this->hostname, ':'); - $easyConnectablePort = ! empty($this->port) && ctype_digit($this->port) ? ':' . $this->port : ''; + $easyConnectablePort = ! empty($this->port) && ctype_digit((string) $this->port) ? ':' . $this->port : ''; $easyConnectableDatabase = $this->database !== '' ? '/' . ltrim($this->database, '/') : ''; if ($isEasyConnectableHostName && ($easyConnectablePort !== '' || $easyConnectableDatabase !== '')) { From 5ee0df20c4f9f9e0194d52da6103cb10b73db84c Mon Sep 17 00:00:00 2001 From: kenjis Date: Sat, 22 Jun 2024 14:57:53 +0900 Subject: [PATCH 4/5] refactor: replace empty() --- phpstan-baseline.php | 2 +- system/Database/OCI8/Connection.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/phpstan-baseline.php b/phpstan-baseline.php index 2351c19b7c3e..1bda1f35594b 100644 --- a/phpstan-baseline.php +++ b/phpstan-baseline.php @@ -3106,7 +3106,7 @@ $ignoreErrors[] = [ // identifier: empty.notAllowed 'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#', - 'count' => 3, + 'count' => 2, 'path' => __DIR__ . '/system/Database/OCI8/Connection.php', ]; $ignoreErrors[] = [ diff --git a/system/Database/OCI8/Connection.php b/system/Database/OCI8/Connection.php index da91f2cc20b0..c3dab9ecc2fc 100644 --- a/system/Database/OCI8/Connection.php +++ b/system/Database/OCI8/Connection.php @@ -632,7 +632,7 @@ protected function buildDSN() } $isEasyConnectableHostName = $this->hostname !== '' && ! str_contains($this->hostname, '/') && ! str_contains($this->hostname, ':'); - $easyConnectablePort = ! empty($this->port) && ctype_digit((string) $this->port) ? ':' . $this->port : ''; + $easyConnectablePort = ($this->port !== '') && ctype_digit((string) $this->port) ? ':' . $this->port : ''; $easyConnectableDatabase = $this->database !== '' ? '/' . ltrim($this->database, '/') : ''; if ($isEasyConnectableHostName && ($easyConnectablePort !== '' || $easyConnectableDatabase !== '')) { From 99346b48aa0b8bdb8b491f640d27640091de95a8 Mon Sep 17 00:00:00 2001 From: kenjis Date: Sat, 22 Jun 2024 17:46:59 +0900 Subject: [PATCH 5/5] refactor: move if conditions to isValidDSN() --- system/Database/OCI8/Connection.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/system/Database/OCI8/Connection.php b/system/Database/OCI8/Connection.php index c3dab9ecc2fc..f7983a695c0c 100644 --- a/system/Database/OCI8/Connection.php +++ b/system/Database/OCI8/Connection.php @@ -104,6 +104,10 @@ class Connection extends BaseConnection */ private function isValidDSN(): bool { + if ($this->DSN === null || $this->DSN === '') { + return false; + } + foreach ($this->validDSNs as $regexp) { if (preg_match($regexp, $this->DSN)) { return true; @@ -120,7 +124,7 @@ private function isValidDSN(): bool */ public function connect(bool $persistent = false) { - if ($this->DSN === null || $this->DSN === '' || ! $this->isValidDSN()) { + if (! $this->isValidDSN()) { $this->buildDSN(); }