Skip to content

Commit

Permalink
The getPDO method can be crushed.
Browse files Browse the repository at this point in the history
  • Loading branch information
muhammetsafak committed Nov 11, 2023
1 parent 22079a8 commit 67cb790
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class Database extends QueryBuilder

private PDO $_pdo;

private bool $isGlobal = false;
private bool $_isGlobal = false;

private static PDO $_globalPDO;

Expand Down Expand Up @@ -139,15 +139,15 @@ public function __call($name, $arguments)
final public function newInstance(array $credentials = []): Database
{
$instance = new Database(empty($credentials) ? $this->_credentials : array_merge($this->_credentials, $credentials));
$instance->isGlobal = false;
$instance->_isGlobal = false;

return $instance;
}

final public function clone(): Database
{
$clone = new self($this->_credentials);
$clone->isGlobal = $this->isGlobal;
$clone->_isGlobal = $this->_isGlobal;

return $clone;
}
Expand Down Expand Up @@ -191,12 +191,12 @@ final public function getError(): array
final public function connectionAsGlobal(): void
{
self::$_globalPDO = $this->getPDO();
$this->isGlobal = true;
$this->_isGlobal = true;
}

final public function getPDO(): PDO
public function getPDO(): PDO
{
if(isset(self::$_globalPDO) && $this->isGlobal){
if(isset(self::$_globalPDO) && $this->_isGlobal){
return self::$_globalPDO;
}
if(!isset($this->_pdo)){
Expand Down Expand Up @@ -246,7 +246,7 @@ final public function withPDO(PDO $pdo): self
{
$with = clone $this;
$with->_pdo = $pdo;
$with->isGlobal = false;
$with->_isGlobal = false;

return $with;
}
Expand Down

0 comments on commit 67cb790

Please sign in to comment.