Make Drupal\Core\Database\Database type strict and PHPStan L10 compliant

Created on 28 June 2025, 4 months ago

Problem/Motivation

Drupal\Core\Database\Database is @final so maybe we can take a stab at making it type-strict.

Proposed resolution

Add declare(strict_types=1); and document types so that the class can be PHPStan L10 compliant.

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

📌 Task
Status

Active

Version

11.0 🔥

Component

database system

Created by

🇮🇹Italy mondrake 🇮🇹

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @mondrake
  • Merge request !12533Closes #3532930 → (Open) created by mondrake
  • Pipeline finished with Failed
    4 months ago
    Total: 207s
    #533922
  • 🇮🇹Italy mondrake 🇮🇹
  • Pipeline finished with Success
    4 months ago
    Total: 1153s
    #533924
  • 🇺🇸United States smustgrave

    What's the pro of using @phpstan-type? Seems tough to read

  • 🇳🇿New Zealand quietone

    Adding tag

  • 🇮🇹Italy mondrake 🇮🇹

    This is not PHPStan level 0... it's PHPStan level 10. If you test locally the patch on the single core/lib/Drupal/Core/Database/Database.php file with PHPStan, and set the level to 10, it will pass.

    I know it's a little bit futuristic but here I am exploring.

    Wrt #4, on higher levels than what we have now PHPStan checks validity of the array keys being used in code against the array shape. Without @phpstan-type defined on the class level as an 'alias' of the array shape, we'd have to enter the full array shape every time it is used (16 times in this class). Readability would get definitely worse as well as the risk of errors (if you start using a new array key, you'd have to change all the instances).

    There's interest in using @phpstan-type, see https://git.drupalcode.org/project/drupal/-/merge_requests/10809#note_51..., but probably not yet enough focus, see https://www.drupal.org/project/drupal/issues/3497431#comment-16102077 📌 Deprecate TestDiscovery test file scanning, use PHPUnit API instead Active and https://www.drupal.org/project/drupal/issues/3082239#comment-15153451 📌 Forbid limited length primary and unique keys, allow only in indexes Needs work (later comments)

    BTW, such long array shapes probably hint at the opportunity to use value objects instead. I opened Introduce a ConnectionParameters object to store database connection parameters Active .

  • Pipeline finished with Failed
    3 months ago
    Total: 427s
    #552445
  • Status changed to RTBC about 2 months ago
  • 🇺🇸United States smustgrave

    I've seen a few of these popup and this one seems well scoped may serve as a good example, lets see what committers think

  • Pipeline finished with Success
    about 1 month ago
    Total: 672s
    #605719
  • Pipeline finished with Success
    23 days ago
    Total: 7514s
    #619405
  • Pipeline finished with Failed
    19 days ago
    Total: 234s
    #624072
  • Pipeline finished with Success
    19 days ago
    Total: 615s
    #624218
  • Pipeline finished with Failed
    19 days ago
    Total: 224s
    #624459
  • Pipeline finished with Success
    19 days ago
    Total: 857s
    #624522
  • Pipeline finished with Success
    19 days ago
    Total: 861s
    #624564
  • Pipeline finished with Success
    2 days ago
    Total: 711s
    #641031
Production build 0.71.5 2024