Skip to content

Commit e7bbbb0

Browse files
committed
Add(typehint) Add typehint to methods and return types
1 parent 773e8ba commit e7bbbb0

File tree

4 files changed

+60
-58
lines changed

4 files changed

+60
-58
lines changed

lib/Doctrine/Connection.php

+11-19
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@
5252
* @version $Revision$
5353
* @author Konsta Vesterinen <[email protected]>
5454
* @author Lukas Smith <[email protected]> (MDB2 library)
55+
*
56+
* @property Doctrine_Export $export
5557
*/
5658
abstract class Doctrine_Connection extends Doctrine_Configurable implements Countable, IteratorAggregate, Serializable
5759
{
@@ -241,41 +243,31 @@ public function isConnected()
241243
}
242244

243245
/**
244-
* getOptions
245-
*
246246
* Get array of all options
247247
*
248-
* @return void
248+
* @return array<string, mixed>
249249
*/
250-
public function getOptions()
250+
public function getOptions(): array
251251
{
252252
return $this->options;
253253
}
254254

255255
/**
256-
* getOption
257-
*
258-
* Retrieves option
259-
*
260-
* @param string $option
261-
* @return void
256+
* @return null|mixed
262257
*/
263-
public function getOption($option)
258+
public function getOption(string $option)
264259
{
265260
if (isset($this->options[$option])) {
266261
return $this->options[$option];
267262
}
268263
}
269264

270265
/**
271-
* setOption
272-
*
273266
* Set option value
274267
*
275-
* @param string $option
276-
* @return void
268+
* @return mixed
277269
*/
278-
public function setOption($option, $value)
270+
public function setOption(string $option, $value)
279271
{
280272
return $this->options[$option] = $value;
281273
}
@@ -1545,8 +1537,8 @@ public function dropDatabase()
15451537
* which is always guaranteed to exist. Mysql: 'mysql', PostgreSQL: 'postgres', etc.
15461538
* This value is set in the Doctrine_Export_{DRIVER} classes if required
15471539
*
1548-
* @param string $info
1549-
* @return void
1540+
* @param array $info
1541+
* @return Doctrine_Connection
15501542
*/
15511543
public function getTmpConnection($info)
15521544
{
@@ -1569,7 +1561,7 @@ public function getTmpConnection($info)
15691561
$username = $this->getOption('username');
15701562
$password = $this->getOption('password');
15711563

1572-
$conn = $this->getManager()->openConnection(array($pdoDsn, $username, $password), 'doctrine_tmp_connection', false);
1564+
$conn = $this->getManager()->openConnection([$pdoDsn, $username, $password], 'doctrine_tmp_connection', false);
15731565
$conn->setOption('username', $username);
15741566
$conn->setOption('password', $password);
15751567

lib/Doctrine/Manager.php

+26-14
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ public static function connection($adapter = null, $name = null)
274274
/**
275275
* Opens a new connection and saves it to Doctrine_Manager->connections
276276
*
277-
* @param PDO|Doctrine_Adapter_Interface $adapter database driver
277+
* @param array|string|PDO|Doctrine_Adapter_Interface $adapter database driver
278278
* @param string $name name of the connection, if empty numeric key is used
279279
* @throws Doctrine_Manager_Exception if trying to bind a connection with an existing name
280280
* @throws Doctrine_Manager_Exception if trying to open connection for unknown driver
@@ -292,17 +292,17 @@ public function openConnection($adapter, $name = null, $setCurrent = true)
292292
if ( ! isset($adapter[0])) {
293293
throw new Doctrine_Manager_Exception('Empty data source name given.');
294294
}
295-
$e = explode(':', $adapter[0]);
295+
$schema = explode(':', $adapter[0]);
296296

297-
if ($e[0] == 'uri') {
298-
$e[0] = 'odbc';
297+
if ($schema[0] === 'uri') {
298+
$schema[0] = 'odbc';
299299
}
300300

301301
$parts['dsn'] = $adapter[0];
302-
$parts['scheme'] = $e[0];
303-
$parts['user'] = (isset($adapter[1])) ? $adapter[1] : null;
304-
$parts['pass'] = (isset($adapter[2])) ? $adapter[2] : null;
305-
$driverName = $e[0];
302+
$parts['scheme'] = $schema[0];
303+
$parts['user'] = $adapter[1] ?? null;
304+
$parts['pass'] = $adapter[2] ?? null;
305+
$driverName = $schema[0];
306306
$adapter = $parts;
307307
} else {
308308
$parts = $this->parseDsn($adapter);
@@ -329,7 +329,7 @@ public function openConnection($adapter, $name = null, $setCurrent = true)
329329
return $this->_connections[$name];
330330
}
331331
} else {
332-
$name = $this->_index;
332+
$name = (string) $this->_index;
333333
$this->_index++;
334334
}
335335

@@ -352,11 +352,23 @@ public function openConnection($adapter, $name = null, $setCurrent = true)
352352
/**
353353
* Parse a pdo style dsn in to an array of parts
354354
*
355-
* @param array $dsn An array of dsn information
356-
* @return array The array parsed
355+
* @param string $dsn An array of dsn information
356+
* @return array{
357+
* dsn: string,
358+
* scheme: string,
359+
* host: ?string,
360+
* user: ?string,
361+
* pass: ?string,
362+
* password: ?string,
363+
* port: ?string,
364+
* path: ?string,
365+
* query: ?string,
366+
* fragment: ?string,
367+
* unix_socket: ?string,
368+
* }
357369
* @todo package:dbal
358370
*/
359-
public function parsePdoDsn($dsn)
371+
public function parsePdoDsn($dsn): array
360372
{
361373
$parts = array();
362374

@@ -401,7 +413,7 @@ public function parsePdoDsn($dsn)
401413
* @param string $dsn
402414
* @return array $parts
403415
*/
404-
protected function _buildDsnPartsArray($dsn)
416+
protected function _buildDsnPartsArray(string $dsn)
405417
{
406418
// fix sqlite dsn so that it will parse correctly
407419
$dsn = str_replace("////", "/", $dsn);
@@ -437,7 +449,7 @@ protected function _buildDsnPartsArray($dsn)
437449
* @return array Parsed contents of DSN
438450
* @todo package:dbal
439451
*/
440-
public function parseDsn($dsn)
452+
public function parseDsn(string $dsn)
441453
{
442454
$parts = $this->_buildDsnPartsArray($dsn);
443455

lib/Doctrine/Migration.php

+21-25
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ public function loadMigrationClass($name, $path = null)
187187
}
188188

189189
if ($class === false) {
190-
return false;
190+
return;
191191
}
192192

193193
if (empty($this->_migrationClasses)) {
@@ -305,17 +305,15 @@ public function getNextMigrationClassVersion()
305305
* migrate to. It will automatically know whether you are migrating up or down
306306
* based on the current version of the database.
307307
*
308-
* @param integer $to Version to migrate to
309-
* @param boolean $dryRun Whether or not to run the migrate process as a dry run
310-
* @return integer $to Version number migrated to
308+
* @param int $to Version to migrate to
309+
* @param bool $dryRun Whether or not to run the migrate process as a dry run
310+
* @return int|false Returns the migration version reached by the migration, false otherwise
311311
* @throws Doctrine_Exception
312312
*/
313313
public function migrate($to = null, $dryRun = false)
314314
{
315315
$this->clearErrors();
316-
317316
$this->_createMigrationTable();
318-
319317
$this->_connection->beginTransaction();
320318

321319
try {
@@ -335,24 +333,22 @@ public function migrate($to = null, $dryRun = false)
335333

336334
if ($dryRun) {
337335
return false;
338-
} else {
339-
$this->_throwErrorsException();
340336
}
341-
} else {
342-
if ($dryRun) {
343-
$this->_connection->rollback();
344-
if ($this->hasErrors()) {
345-
return false;
346-
} else {
347-
return $to;
348-
}
349-
} else {
350-
$this->_connection->commit();
351-
$this->setCurrentVersion($to);
352-
return $to;
337+
$this->_throwErrorsException();
338+
}
339+
340+
if ($dryRun) {
341+
$this->_connection->rollback();
342+
if ($this->hasErrors()) {
343+
return false;
353344
}
345+
return $to;
354346
}
355-
return false;
347+
348+
$this->_connection->commit();
349+
$this->setCurrentVersion($to);
350+
351+
return $to;
356352
}
357353

358354
/**
@@ -435,12 +431,12 @@ public function getMigrationClass($num)
435431
}
436432

437433
/**
438-
* Throw an exception with all the errors trigged during the migration
434+
* Throw an exception with all the errors triggered during the migration
439435
*
440-
* @return void
441-
* @throws Doctrine_Migration_Exception $e
436+
* @return never-returns
437+
* @throws Doctrine_Migration_Exception
442438
*/
443-
protected function _throwErrorsException()
439+
protected function _throwErrorsException(): void
444440
{
445441
$messages = array();
446442
$num = 0;

tests/DoctrineTest/Doctrine_UnitTestCase.php

+2
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ public function init()
216216
}
217217
}
218218
}
219+
219220
public function prepareTables() {
220221
foreach($this->tables as $name) {
221222
$name = ucwords($name);
@@ -230,6 +231,7 @@ public function prepareTables() {
230231
$this->conn->export->exportClasses($this->tables);
231232
$this->objTable = $this->connection->getTable('User');
232233
}
234+
233235
public function prepareData()
234236
{
235237
$groups = new Doctrine_Collection($this->connection->getTable('Group'));

0 commit comments

Comments
 (0)