Skip to content

Commit ab64aeb

Browse files
authored
Merge pull request #8986 from kenjis/fix-OCI8-connect
fix: [OCI8] if conditions to build DSN
2 parents 9d02066 + 99346b4 commit ab64aeb

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

phpstan-baseline.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3070,7 +3070,7 @@
30703070
$ignoreErrors[] = [
30713071
// identifier: empty.notAllowed
30723072
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
3073-
'count' => 5,
3073+
'count' => 2,
30743074
'path' => __DIR__ . '/system/Database/OCI8/Connection.php',
30753075
];
30763076
$ignoreErrors[] = [

system/Database/OCI8/Connection.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ class Connection extends BaseConnection
104104
*/
105105
private function isValidDSN(): bool
106106
{
107+
if ($this->DSN === null || $this->DSN === '') {
108+
return false;
109+
}
110+
107111
foreach ($this->validDSNs as $regexp) {
108112
if (preg_match($regexp, $this->DSN)) {
109113
return true;
@@ -120,13 +124,13 @@ private function isValidDSN(): bool
120124
*/
121125
public function connect(bool $persistent = false)
122126
{
123-
if (empty($this->DSN) && ! $this->isValidDSN()) {
127+
if (! $this->isValidDSN()) {
124128
$this->buildDSN();
125129
}
126130

127131
$func = $persistent ? 'oci_pconnect' : 'oci_connect';
128132

129-
return empty($this->charset)
133+
return ($this->charset === '')
130134
? $func($this->username, $this->password, $this->DSN)
131135
: $func($this->username, $this->password, $this->DSN, $this->charset);
132136
}
@@ -632,7 +636,7 @@ protected function buildDSN()
632636
}
633637

634638
$isEasyConnectableHostName = $this->hostname !== '' && ! str_contains($this->hostname, '/') && ! str_contains($this->hostname, ':');
635-
$easyConnectablePort = ! empty($this->port) && ctype_digit($this->port) ? ':' . $this->port : '';
639+
$easyConnectablePort = ($this->port !== '') && ctype_digit((string) $this->port) ? ':' . $this->port : '';
636640
$easyConnectableDatabase = $this->database !== '' ? '/' . ltrim($this->database, '/') : '';
637641

638642
if ($isEasyConnectableHostName && ($easyConnectablePort !== '' || $easyConnectableDatabase !== '')) {

0 commit comments

Comments
 (0)