Skip to content

Tightened 'DrupalDriverInterface' contract and 'DrupalDriver' visibility.#358

Merged
AlexSkrypnyk merged 1 commit intomasterfrom
feature/driver-interface
Apr 28, 2026
Merged

Tightened 'DrupalDriverInterface' contract and 'DrupalDriver' visibility.#358
AlexSkrypnyk merged 1 commit intomasterfrom
feature/driver-interface

Conversation

@AlexSkrypnyk
Copy link
Copy Markdown
Collaborator

@AlexSkrypnyk AlexSkrypnyk commented Apr 28, 2026

Summary

Tightens the DrupalDriverInterface contract so consumers can type-hint against the interface and call getCore(), setCore(), and getDrupalVersion() without downcasting to the concrete class. Makes $core and $version on DrupalDriver protected so subclasses retain access while outside callers are directed through the public API. Corrects the @throws BootstrapException annotation on getDrupalVersion() - the exception is raised during construction inside detectMajorVersion(), not by the getter itself.

Stack

This PR is #1 of 4 in a stacked series:

  • PR 1 (this one): feature/driver-interfacemaster
  • PR 2: feature/field-classifierfeature/driver-interface
  • PR 3: feature/field-coveragefeature/field-classifier
  • PR 4: feature/ext-smoke-cifeature/field-coverage

Merge PRs in order. Each PR's base will rebase to master automatically as its predecessor merges.

Changes

  • Declares getCore(), setCore(), and getDrupalVersion() on DrupalDriverInterface so the full driver contract is visible at the interface level.
  • Makes $core and $version properties protected on DrupalDriver; subclasses can read them, but external callers must use the public methods.
  • Corrects the @throws BootstrapException annotation on getDrupalVersion(): the exception originates in detectMajorVersion() at construction time, not in the getter. The updated docblock on the interface makes this distinction clear.

Before / After

Before                              After
------                              -----
DrupalDriverInterface               DrupalDriverInterface
  (no getCore / setCore /             + getCore(): CoreInterface
   getDrupalVersion declared)         + setCore(CoreInterface): void
                                      + getDrupalVersion(): int

DrupalDriver                        DrupalDriver
  public $core                        protected $core
  public $version                     protected $version
  getDrupalVersion()                  getDrupalVersion()
    @throws BootstrapException          (no @throws - exception
                                         is raised at construction)

Summary by CodeRabbit

  • Refactor

    • Improved internal property encapsulation in the DrupalDriver class
    • Expanded DrupalDriverInterface to include core delegation and version introspection methods
  • Tests

    • Updated unit tests to align with internal property visibility changes

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 28, 2026

📝 Walkthrough

Walkthrough

This PR refactors the DrupalDriver class by converting public properties ($core and $version) to protected visibility while adding interface-level contracts for property access through getter and setter methods. Docblocks are consolidated to inherit documentation. Test utilities are updated to use reflection and the public setCore() method instead of direct property assignment.

Changes

Cohort / File(s) Summary
Core Encapsulation
src/Drupal/Driver/DrupalDriver.php, src/Drupal/Driver/DrupalDriverInterface.php
Property visibility restricted from public to protected for $core and $version. Interface expanded with three new method contracts: getCore(), setCore(), and getDrupalVersion(). Docblocks updated to {@inheritdoc} for getter and setter methods.
Test Utilities
tests/Drupal/Tests/Driver/Unit/CoreLookupTest.php, tests/Drupal/Tests/Driver/Unit/DrupalDriverDelegationTest.php
Helper methods refactored to use reflection-based property setting and public setCore() method instead of direct property assignment, aligning test setup with encapsulation changes.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

Poem

🐰 Protected properties, now so shy,
Behind the interface they gently lie,
With getters and setters to show the way,
Encapsulation saves the day!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title accurately and concisely summarizes the main changes: tightening the DrupalDriverInterface contract by adding method declarations and restricting DrupalDriver visibility by making properties protected.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/driver-interface

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown

Code coverage (threshold: 95%)



Code Coverage Report Summary:
  Classes: 95.45% (21/22)
  Methods: 99.39% (164/165)
  Lines:   99.87% (773/774)

Per-class coverage
Drupal\Driver\BlackboxDriver                                 100.00%
Drupal\Driver\Core\Core                                       99.68%
Drupal\Driver\Core\Field\AbstractHandler                     100.00%
Drupal\Driver\Core\Field\AddressHandler                      100.00%
Drupal\Driver\Core\Field\BooleanHandler                      100.00%
Drupal\Driver\Core\Field\DaterangeHandler                    100.00%
Drupal\Driver\Core\Field\DatetimeHandler                     100.00%
Drupal\Driver\Core\Field\DefaultHandler                      100.00%
Drupal\Driver\Core\Field\EmbridgeAssetItemHandler              0.00%
Drupal\Driver\Core\Field\EntityReferenceHandler              100.00%
Drupal\Driver\Core\Field\FileHandler                         100.00%
Drupal\Driver\Core\Field\ImageHandler                        100.00%
Drupal\Driver\Core\Field\LinkHandler                         100.00%
Drupal\Driver\Core\Field\ListFloatHandler                      0.00%
Drupal\Driver\Core\Field\ListHandlerBase                     100.00%
Drupal\Driver\Core\Field\ListIntegerHandler                    0.00%
Drupal\Driver\Core\Field\ListStringHandler                     0.00%
Drupal\Driver\Core\Field\NameHandler                         100.00%
Drupal\Driver\Core\Field\OgStandardReferenceHandler            0.00%
Drupal\Driver\Core\Field\SupportedImageHandler               100.00%
Drupal\Driver\Core\Field\TextWithSummaryHandler              100.00%
Drupal\Driver\Core\Field\TimeHandler                         100.00%
Drupal\Driver\DrupalDriver                                   100.00%
Drupal\Driver\DrushDriver                                    100.00%
Drupal\Driver\Exception\BootstrapException                   100.00%
Drupal\Driver\Exception\Exception                            100.00%
Drupal\Driver\Exception\UnsupportedDriverActionException     100.00%

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/Drupal/Driver/DrupalDriver.php`:
- Around line 143-145: The setCore(CoreInterface $core) method currently
replaces $this->core without resetting the driver's bootstrapped flag; update
setCore to assign the new core and also set $this->bootstrapped = false (and
clear any related bootstrap-specific state if present) so the driver will re-run
bootstrap for the new core; modify the setCore function in DrupalDriver to reset
the bootstrapped property after assigning $this->core.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 3ae51423-2b22-48ec-ade6-3e2928e7cc6a

📥 Commits

Reviewing files that changed from the base of the PR and between 5a87074 and 69bfa5a.

📒 Files selected for processing (4)
  • src/Drupal/Driver/DrupalDriver.php
  • src/Drupal/Driver/DrupalDriverInterface.php
  • tests/Drupal/Tests/Driver/Unit/CoreLookupTest.php
  • tests/Drupal/Tests/Driver/Unit/DrupalDriverDelegationTest.php

Comment on lines +143 to +145
public function setCore(CoreInterface $core): void {
$this->core = $core;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Reset bootstrapped state when replacing core.

On Line 143-144, replacing the core without resetting bootstrapped can leave the driver in an inconsistent state (new core, old bootstrap flag), causing bootstrap to be skipped incorrectly.

Proposed fix
   public function setCore(CoreInterface $core): void {
     $this->core = $core;
+    $this->bootstrapped = FALSE;
   }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/Drupal/Driver/DrupalDriver.php` around lines 143 - 145, The
setCore(CoreInterface $core) method currently replaces $this->core without
resetting the driver's bootstrapped flag; update setCore to assign the new core
and also set $this->bootstrapped = false (and clear any related
bootstrap-specific state if present) so the driver will re-run bootstrap for the
new core; modify the setCore function in DrupalDriver to reset the bootstrapped
property after assigning $this->core.

@AlexSkrypnyk AlexSkrypnyk merged commit 86c2e4b into master Apr 28, 2026
12 checks passed
@AlexSkrypnyk AlexSkrypnyk deleted the feature/driver-interface branch April 28, 2026 08:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant