Skip to content

Commit

Permalink
Add(typehint) Add typehint to methods and return types
Browse files Browse the repository at this point in the history
  • Loading branch information
thePanz committed Jun 27, 2024
1 parent f47a790 commit 2961835
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 36 deletions.
28 changes: 10 additions & 18 deletions lib/Doctrine/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
* @version $Revision$
* @author Konsta Vesterinen <[email protected]>
* @author Lukas Smith <[email protected]> (MDB2 library)
*
* @property Doctrine_Export $export
*/
abstract class Doctrine_Connection extends Doctrine_Configurable implements Countable, IteratorAggregate, Serializable
{
Expand Down Expand Up @@ -241,41 +243,31 @@ public function isConnected()
}

/**
* getOptions
*
* Get array of all options
*
* @return void
* @return array<string, mixed>
*/
public function getOptions()
{
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];
}
}

/**
* 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;
}
Expand Down Expand Up @@ -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)
{
Expand All @@ -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);

Expand Down
40 changes: 26 additions & 14 deletions lib/Doctrine/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand All @@ -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++;
}

Expand All @@ -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();

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down
6 changes: 2 additions & 4 deletions lib/Doctrine/Migration.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public function loadMigrationClass($name, $path = null)
}

if ($class === false) {
return false;
return;
}

if (empty($this->_migrationClasses)) {
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions tests/DoctrineTest/Doctrine_UnitTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ public function init()
}
}
}

public function prepareTables() {
foreach($this->tables as $name) {
$name = ucwords($name);
Expand All @@ -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'));
Expand Down

0 comments on commit 2961835

Please sign in to comment.