diff --git a/lib/Doctrine/Connection.php b/lib/Doctrine/Connection.php index 73a7e5fa..6bb9e7ce 100644 --- a/lib/Doctrine/Connection.php +++ b/lib/Doctrine/Connection.php @@ -52,6 +52,8 @@ * @version $Revision$ * @author Konsta Vesterinen * @author Lukas Smith (MDB2 library) + * + * @property Doctrine_Export $export */ abstract class Doctrine_Connection extends Doctrine_Configurable implements Countable, IteratorAggregate, Serializable { @@ -241,26 +243,19 @@ public function isConnected() } /** - * getOptions - * * Get array of all options * - * @return void + * @return array */ - public function getOptions() + public function getOptions(): array { return $this->options; } /** - * getOption - * - * Retrieves option - * - * @param string $option - * @return void + * @return null|mixed */ - public function getOption($option) + public function getOption(string $option) { if (isset($this->options[$option])) { return $this->options[$option]; @@ -268,14 +263,11 @@ public function getOption($option) } /** - * setOption - * * Set option value * - * @param string $option - * @return void + * @return mixed */ - public function setOption($option, $value) + public function setOption(string $option, $value) { return $this->options[$option] = $value; } @@ -1545,8 +1537,8 @@ public function dropDatabase() * which is always guaranteed to exist. Mysql: 'mysql', PostgreSQL: 'postgres', etc. * This value is set in the Doctrine_Export_{DRIVER} classes if required * - * @param string $info - * @return void + * @param array $info + * @return Doctrine_Connection */ public function getTmpConnection($info) { @@ -1569,7 +1561,7 @@ public function getTmpConnection($info) $username = $this->getOption('username'); $password = $this->getOption('password'); - $conn = $this->getManager()->openConnection(array($pdoDsn, $username, $password), 'doctrine_tmp_connection', false); + $conn = $this->getManager()->openConnection([$pdoDsn, $username, $password], 'doctrine_tmp_connection', false); $conn->setOption('username', $username); $conn->setOption('password', $password); diff --git a/lib/Doctrine/Manager.php b/lib/Doctrine/Manager.php index a2b08944..9c07f8d3 100644 --- a/lib/Doctrine/Manager.php +++ b/lib/Doctrine/Manager.php @@ -274,7 +274,7 @@ public static function connection($adapter = null, $name = null) /** * Opens a new connection and saves it to Doctrine_Manager->connections * - * @param PDO|Doctrine_Adapter_Interface $adapter database driver + * @param array|string|PDO|Doctrine_Adapter_Interface $adapter database driver * @param string $name name of the connection, if empty numeric key is used * @throws Doctrine_Manager_Exception if trying to bind a connection with an existing name * @throws Doctrine_Manager_Exception if trying to open connection for unknown driver @@ -292,17 +292,17 @@ public function openConnection($adapter, $name = null, $setCurrent = true) if ( ! isset($adapter[0])) { throw new Doctrine_Manager_Exception('Empty data source name given.'); } - $e = explode(':', $adapter[0]); + $schema = explode(':', $adapter[0]); - if ($e[0] == 'uri') { - $e[0] = 'odbc'; + if ($schema[0] === 'uri') { + $schema[0] = 'odbc'; } $parts['dsn'] = $adapter[0]; - $parts['scheme'] = $e[0]; - $parts['user'] = (isset($adapter[1])) ? $adapter[1] : null; - $parts['pass'] = (isset($adapter[2])) ? $adapter[2] : null; - $driverName = $e[0]; + $parts['scheme'] = $schema[0]; + $parts['user'] = $adapter[1] ?? null; + $parts['pass'] = $adapter[2] ?? null; + $driverName = $schema[0]; $adapter = $parts; } else { $parts = $this->parseDsn($adapter); @@ -329,7 +329,7 @@ public function openConnection($adapter, $name = null, $setCurrent = true) return $this->_connections[$name]; } } else { - $name = $this->_index; + $name = (string) $this->_index; $this->_index++; } @@ -352,11 +352,23 @@ public function openConnection($adapter, $name = null, $setCurrent = true) /** * Parse a pdo style dsn in to an array of parts * - * @param array $dsn An array of dsn information - * @return array The array parsed + * @param string $dsn An array of dsn information + * @return array{ + * dsn: string, + * scheme: string, + * host: ?string, + * user: ?string, + * pass: ?string, + * password: ?string, + * port: ?string, + * path: ?string, + * query: ?string, + * fragment: ?string, + * unix_socket: ?string, + * } * @todo package:dbal */ - public function parsePdoDsn($dsn) + public function parsePdoDsn($dsn): array { $parts = array(); @@ -401,7 +413,7 @@ public function parsePdoDsn($dsn) * @param string $dsn * @return array $parts */ - protected function _buildDsnPartsArray($dsn) + protected function _buildDsnPartsArray(string $dsn) { // fix sqlite dsn so that it will parse correctly $dsn = str_replace("////", "/", $dsn); @@ -437,7 +449,7 @@ protected function _buildDsnPartsArray($dsn) * @return array Parsed contents of DSN * @todo package:dbal */ - public function parseDsn($dsn) + public function parseDsn(string $dsn) { $parts = $this->_buildDsnPartsArray($dsn); diff --git a/lib/Doctrine/Migration.php b/lib/Doctrine/Migration.php index 0208ce54..e05eed9f 100644 --- a/lib/Doctrine/Migration.php +++ b/lib/Doctrine/Migration.php @@ -187,7 +187,7 @@ public function loadMigrationClass($name, $path = null) } if ($class === false) { - return false; + return; } if (empty($this->_migrationClasses)) { @@ -305,17 +305,15 @@ public function getNextMigrationClassVersion() * migrate to. It will automatically know whether you are migrating up or down * based on the current version of the database. * - * @param integer $to Version to migrate to - * @param boolean $dryRun Whether or not to run the migrate process as a dry run - * @return integer $to Version number migrated to + * @param int $to Version to migrate to + * @param bool $dryRun Whether or not to run the migrate process as a dry run + * @return int|false Returns the migration version reached by the migration, false otherwise * @throws Doctrine_Exception */ public function migrate($to = null, $dryRun = false) { $this->clearErrors(); - $this->_createMigrationTable(); - $this->_connection->beginTransaction(); try { @@ -335,24 +333,22 @@ public function migrate($to = null, $dryRun = false) if ($dryRun) { return false; - } else { - $this->_throwErrorsException(); } - } else { - if ($dryRun) { - $this->_connection->rollback(); - if ($this->hasErrors()) { - return false; - } else { - return $to; - } - } else { - $this->_connection->commit(); - $this->setCurrentVersion($to); - return $to; + $this->_throwErrorsException(); + } + + if ($dryRun) { + $this->_connection->rollback(); + if ($this->hasErrors()) { + return false; } + return $to; } - return false; + + $this->_connection->commit(); + $this->setCurrentVersion($to); + + return $to; } /** @@ -435,12 +431,12 @@ public function getMigrationClass($num) } /** - * Throw an exception with all the errors trigged during the migration + * Throw an exception with all the errors triggered during the migration * - * @return void - * @throws Doctrine_Migration_Exception $e + * @return never-returns + * @throws Doctrine_Migration_Exception */ - protected function _throwErrorsException() + protected function _throwErrorsException(): void { $messages = array(); $num = 0; diff --git a/tests/DoctrineTest/Doctrine_UnitTestCase.php b/tests/DoctrineTest/Doctrine_UnitTestCase.php index 3fa7bcbc..c158d5da 100644 --- a/tests/DoctrineTest/Doctrine_UnitTestCase.php +++ b/tests/DoctrineTest/Doctrine_UnitTestCase.php @@ -216,6 +216,7 @@ public function init() } } } + public function prepareTables() { foreach($this->tables as $name) { $name = ucwords($name); @@ -230,6 +231,7 @@ public function prepareTables() { $this->conn->export->exportClasses($this->tables); $this->objTable = $this->connection->getTable('User'); } + public function prepareData() { $groups = new Doctrine_Collection($this->connection->getTable('Group'));