From 29618352f7f14ed40beb63db1beabebcde9c9d37 Mon Sep 17 00:00:00 2001 From: thePanz Date: Thu, 27 Jun 2024 16:44:54 +0200 Subject: [PATCH] Add(typehint) Add typehint to methods and return types --- lib/Doctrine/Connection.php | 28 +++++--------- lib/Doctrine/Manager.php | 40 +++++++++++++------- lib/Doctrine/Migration.php | 6 +-- tests/DoctrineTest/Doctrine_UnitTestCase.php | 2 + 4 files changed, 40 insertions(+), 36 deletions(-) diff --git a/lib/Doctrine/Connection.php b/lib/Doctrine/Connection.php index 73a7e5fa7..479fcfd94 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,11 +243,9 @@ public function isConnected() } /** - * getOptions - * * Get array of all options * - * @return void + * @return array */ public function getOptions() { @@ -253,14 +253,9 @@ public function getOptions() } /** - * 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 a2b08944d..9c07f8d3e 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 0208ce540..c62caed35 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)) { @@ -307,15 +307,13 @@ public function getNextMigrationClassVersion() * * @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 + * @return bool True if the migration succeeded, false otherwise * @throws Doctrine_Exception */ public function migrate($to = null, $dryRun = false) { $this->clearErrors(); - $this->_createMigrationTable(); - $this->_connection->beginTransaction(); try { diff --git a/tests/DoctrineTest/Doctrine_UnitTestCase.php b/tests/DoctrineTest/Doctrine_UnitTestCase.php index 3fa7bcbcd..c158d5da2 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'));