Verified Commit 3a8ca189 authored by Dave Long's avatar Dave Long
Browse files

refactor: #3532930 Make Drupal\Core\Database\Database type strict and PHPStan L10 compliant

By: mondrake
By: smustgrave
By: longwave
By: alexpott
By: mradcliffe
parent 39b62a82
Loading
Loading
Loading
Loading
+0 −36
Changes for core/.phpstan-baseline.php: 0 added lines, 36 removed lines.
Original line number Diff line number Diff line
@@ -3319,42 +3319,6 @@
	'count' => 1,
	'path' => __DIR__ . '/lib/Drupal/Core/Database/Connection.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\Core\\\\Database\\\\Database\\:\\:addConnectionInfo\\(\\) has no return type specified\\.$#',
	'identifier' => 'missingType.return',
	'count' => 1,
	'path' => __DIR__ . '/lib/Drupal/Core/Database/Database.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\Core\\\\Database\\\\Database\\:\\:closeConnection\\(\\) has no return type specified\\.$#',
	'identifier' => 'missingType.return',
	'count' => 1,
	'path' => __DIR__ . '/lib/Drupal/Core/Database/Database.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\Core\\\\Database\\\\Database\\:\\:ignoreTarget\\(\\) has no return type specified\\.$#',
	'identifier' => 'missingType.return',
	'count' => 1,
	'path' => __DIR__ . '/lib/Drupal/Core/Database/Database.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\Core\\\\Database\\\\Database\\:\\:openConnection\\(\\) has no return type specified\\.$#',
	'identifier' => 'missingType.return',
	'count' => 1,
	'path' => __DIR__ . '/lib/Drupal/Core/Database/Database.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\Core\\\\Database\\\\Database\\:\\:parseConnectionInfo\\(\\) has no return type specified\\.$#',
	'identifier' => 'missingType.return',
	'count' => 1,
	'path' => __DIR__ . '/lib/Drupal/Core/Database/Database.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\Core\\\\Database\\\\Database\\:\\:setMultipleConnectionInfo\\(\\) has no return type specified\\.$#',
	'identifier' => 'missingType.return',
	'count' => 1,
	'path' => __DIR__ . '/lib/Drupal/Core/Database/Database.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\Core\\\\Database\\\\Install\\\\Tasks\\:\\:checkEngineVersion\\(\\) has no return type specified\\.$#',
	'identifier' => 'missingType.return',
+6 −0
Changes for core/lib/Drupal/Core/Database/Connection.php: 6 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -512,6 +512,9 @@ protected function preprocessStatement(string $query, array $options): string {
   *   (optional) The target this connection is for.
   */
  public function setTarget($target = NULL) {
    if (!is_string($target)) {
      @trigger_error('Passing a non-string value to the $target parameter in ' . __METHOD__ . '() is deprecated in drupal:11.5.0 and is removed from drupal:13.0.0. Pass only string values instead. See https://www.drupal.org/node/3577925', E_USER_DEPRECATED);
    }
    if (!isset($this->target)) {
      $this->target = $target;
    }
@@ -534,6 +537,9 @@ public function getTarget() {
   *   The key this connection is for.
   */
  public function setKey($key) {
    if (!is_string($key)) {
      @trigger_error('Passing a non-string value to the $key parameter in ' . __METHOD__ . '() is deprecated in drupal:11.5.0 and is removed from drupal:13.0.0. Pass only string values instead. See https://www.drupal.org/node/3577925', E_USER_DEPRECATED);
    }
    if (!isset($this->key)) {
      $this->key = $key;
    }
+207 −104

File changed.

Preview size limit exceeded, changes collapsed.

+14 −2
Changes for core/lib/Drupal/Core/Database/Log.php: 14 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -14,6 +14,15 @@
 *
 * Every connection has one and only one logging object on it for all targets
 * and logging keys.
 *
 * @phpstan-type DatabaseLogEntry array{
 *   'query': string,
 *   'args': list<mixed>,
 *   'caller': string,
 *   'target': string,
 *   'time': float,
 *   'start': float,
 * }
 */
class Log {

@@ -22,7 +31,7 @@ class Log {
   *
   * This will only be used if the query logger is enabled.
   *
   * @var array
   * @var array<string,list<DatabaseLogEntry>>
   *   The structure for the logging array is as follows:
   *
   * @code
@@ -50,6 +59,9 @@ class Log {
   *   The database connection key for which to enable logging.
   */
  public function __construct($key = 'default') {
    if (!is_string($key)) {
      @trigger_error('Passing a non-string value to the $key parameter in ' . __METHOD__ . '() is deprecated in drupal:11.5.0 and is removed from drupal:13.0.0. Pass only string values instead. See https://www.drupal.org/node/3577925', E_USER_DEPRECATED);
    }
    $this->connectionKey = $key;
  }

@@ -75,7 +87,7 @@ public function start($logging_key) {
   * @param string $logging_key
   *   The logging key to fetch.
   *
   * @return array
   * @return list<DatabaseLogEntry>
   *   An indexed array of all query records for this logging key.
   */
  public function get($logging_key) {
+1 −1
Changes for core/lib/Drupal/Core/Extension/DatabaseDriver.php: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -158,7 +158,7 @@ public function getInstallTasks(): Tasks {
   * @return array{
   *     'autoload': string,
   *     'namespace': string,
   *     'dependencies': array<string, array{'autoload': string, 'namespace': string}>,
   *     'dependencies'?: array<string, array{'autoload': string, 'namespace': string}>,
   *   }
   */
  // phpcs:enable
Loading