Browse Source

Remove redundant return type.

Connection/driver always return on success and throw an exception on failure.
This makes the return type redundant.
ADmad 4 years ago
parent
commit
b1a063dc4b

+ 3 - 3
src/Database/Connection.php

@@ -228,12 +228,12 @@ class Connection implements ConnectionInterface
      * Connects to the configured database.
      *
      * @throws \Cake\Database\Exception\MissingConnectionException If database connection could not be established.
-     * @return bool true, if the connection was already established or the attempt was successful.
+     * @return void
      */
-    public function connect(): bool
+    public function connect(): void
     {
         try {
-            return $this->_driver->connect();
+            $this->_driver->connect();
         } catch (MissingConnectionException $e) {
             throw $e;
         } catch (Throwable $e) {

+ 3 - 5
src/Database/Driver.php

@@ -113,9 +113,9 @@ abstract class Driver implements DriverInterface
      *
      * @param string $dsn A Driver-specific PDO-DSN
      * @param array<string, mixed> $config configuration to be used for creating connection
-     * @return bool true on success
+     * @return void
      */
-    protected function _connect(string $dsn, array $config): bool
+    protected function _connect(string $dsn, array $config): void
     {
         $action = function () use ($dsn, $config): void {
             $this->setConnection(new PDO(
@@ -141,14 +141,12 @@ abstract class Driver implements DriverInterface
         } finally {
             $this->connectRetries = $retry->getRetries();
         }
-
-        return true;
     }
 
     /**
      * @inheritDoc
      */
-    abstract public function connect(): bool;
+    abstract public function connect(): void;
 
     /**
      * @inheritDoc

+ 3 - 7
src/Database/Driver/Mysql.php

@@ -118,14 +118,12 @@ class Mysql extends Driver
     ];
 
     /**
-     * Establishes a connection to the database server
-     *
-     * @return bool true on success
+     * @inheritDoc
      */
-    public function connect(): bool
+    public function connect(): void
     {
         if ($this->_connection) {
-            return true;
+            return;
         }
         $config = $this->_config;
 
@@ -169,8 +167,6 @@ class Mysql extends Driver
                 $connection->exec($command);
             }
         }
-
-        return true;
     }
 
     /**

+ 3 - 7
src/Database/Driver/Postgres.php

@@ -80,14 +80,12 @@ class Postgres extends Driver
     protected string $_endQuote = '"';
 
     /**
-     * Establishes a connection to the database server
-     *
-     * @return bool true on success
+     * @inheritDoc
      */
-    public function connect(): bool
+    public function connect(): void
     {
         if ($this->_connection) {
-            return true;
+            return;
         }
         $config = $this->_config;
         $config['flags'] += [
@@ -118,8 +116,6 @@ class Postgres extends Driver
         foreach ($config['init'] as $command) {
             $connection->exec($command);
         }
-
-        return true;
     }
 
     /**

+ 3 - 7
src/Database/Driver/Sqlite.php

@@ -110,14 +110,12 @@ class Sqlite extends Driver
     ];
 
     /**
-     * Establishes a connection to the database server
-     *
-     * @return bool true on success
+     * @inheritDoc
      */
-    public function connect(): bool
+    public function connect(): void
     {
         if ($this->_connection) {
-            return true;
+            return;
         }
         $config = $this->_config;
         $config['flags'] += [
@@ -148,8 +146,6 @@ class Sqlite extends Driver
                 $this->getConnection()->exec($command);
             }
         }
-
-        return true;
     }
 
     /**

+ 3 - 5
src/Database/Driver/Sqlserver.php

@@ -107,12 +107,12 @@ class Sqlserver extends Driver
      * information see: https://github.com/Microsoft/msphpsql/issues/65).
      *
      * @throws \InvalidArgumentException if an unsupported setting is in the driver config
-     * @return bool true on success
+     * @return void
      */
-    public function connect(): bool
+    public function connect(): void
     {
         if ($this->_connection) {
-            return true;
+            return;
         }
         $config = $this->_config;
 
@@ -169,8 +169,6 @@ class Sqlserver extends Driver
                 $connection->setAttribute($key, $value);
             }
         }
-
-        return true;
     }
 
     /**

+ 2 - 2
src/Database/DriverInterface.php

@@ -64,9 +64,9 @@ interface DriverInterface
      * Establishes a connection to the database server.
      *
      * @throws \Cake\Database\Exception\MissingConnectionException If database connection could not be established.
-     * @return bool True on success, false on failure.
+     * @return void
      */
-    public function connect(): bool;
+    public function connect();
 
     /**
      * Disconnects from database server.

+ 2 - 2
tests/TestCase/Database/ConnectionTest.php

@@ -123,9 +123,9 @@ class ConnectionTest extends TestCase
     /**
      * Tests connecting to database
      */
-    public function testConnect(): void
+    public function testIsConnect(): void
     {
-        $this->assertTrue($this->connection->connect());
+        $this->connection->connect();
         $this->assertTrue($this->connection->isConnected());
     }