Problem/Motivation

The migrate stubbing service (\Drupal\migrate\MigrateStub) implements \Drupal\migrate\MigrateStubInterface, but overrides the method signature and description.

As the result, the following line in the MigrationLookup.php file is highlighted because the method call doesn't match the method signature (3 parameters vs 4 parameters).

Proposed resolution

1) Add missing parameter to the interface method signature;
2) Move the method description from the service to the interface and use inheritance.

Issue fork drupal-3184552

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Matroskeen created an issue. See original summary.

Matroskeen’s picture

Status: Active » Needs review
Issue tags: +Bug Smash Initiative
Matroskeen’s picture

Issue summary: View changes
Matroskeen’s picture

Title: MigrateStub method declaration should follow MigrateStubInterface » MigrateStub service should use MigrateStubInterface method declaration
benjifisher’s picture

Status: Needs review » Needs work

All of this code was added in #3004927: Create Migration Lookup and Stub services. If you search that page for "createStub", then you will see that this additional parameter is discussed in #3004927-36: Create Migration Lookup and Stub services(4) and #3004927-37: Create Migration Lookup and Stub services. The difference between the interface and the implementation is intentional.

In general, it is not a problem if an implementation adds an optional parameter to the function signature.

What is a problem would be changing the function signature in the interface. There may be non-core modules that implement MigrateStubInterface, and they will break if we do that.

Perhaps we should change the type hint in MigrationLookup from MigrateStubInterface to MigrateStub. If we do that, then we should add a code comment explaining why.

mikelutz’s picture

Yeah, this is intentional, and we can't add the parameter to the interface without breaking BC. The correct path forward is to deprecate and replace the migration_lookup plugin with a new version that doesn't need the 4th parameter (migration_lookup does because of backwards compatibility reasons). Once that's done the fourth parameter can be deprecated and removed.

Matroskeen’s picture

Status: Needs work » Needs review

How about this? We keep MigrateStubInterface in the constructor (because it might be swapped) but changing a type hint in the property doc block. In this case, IDE doesn't complain anymore and it makes me happy.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

mikelutz’s picture

Status: Needs review » Needs work
Related issues: +#3246666: Deprecate migrate_lookup and replace with cleaner process plugin

I don't completely object to this, but at minimum for now it needs at least a comment explaining why we aren't typehinting on the interface. Changing the phpdoc won't break anything, but it's still wrong. The constructor takes an interface, the create method pulls the service, which is only guaranteed to be the interface. Essentially we are assuming that no one has replaced the stub service in custom code.

In retrospec, Maybe I should have had type checking to make sure that the MigrateStub service is actually the Core MigrateStub class, and errored out if we got something different, but this whole plugin really defeats the purpose of having that as an injectable service. Ultimately, the migrate_lookup plugin needs to be deprecated and replaced with a cleaner version.

I created #3246666: Deprecate migrate_lookup and replace with cleaner process plugin to do that, but with an extra comment in there, I don't object to changing the docblock for the class property.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.