Problem/Motivation

PHPStan baseline is currently skipping multiple Call to an undefined method errors.

Proposed resolution

Fix migrate destination entity errors, clean up the baseline.

Issue fork drupal-3318888

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:

Comments

mondrake created an issue. See original summary.

mondrake’s picture

Status: Active » Needs review
StatusFileSize
new3.35 KB
mondrake’s picture

StatusFileSize
new3.26 KB
mondrake’s picture

StatusFileSize
new3.26 KB
longwave’s picture

Are EntityConfigBase and EntityContentBase the only two valid immediate child classes, and all users are expected to only extend them? If so we could make these abstract now?

smustgrave’s picture

Should this go back to NW for discovery?

mondrake’s picture

Status: Needs review » Needs work

Yes

mondrake’s picture

Status: Needs work » Needs review
StatusFileSize
new2.37 KB

Let's try #5.

smustgrave’s picture

Free to review once it's done. If I don't get to it today just ping me on the #needs-review-queue channel and can take a look

mondrake’s picture

StatusFileSize
new2.37 KB

Better luck?

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Changes in #10 look good to me.

xjm’s picture

Status: Reviewed & tested by the community » Needs work

I looked at where these two methods are used in core to confirm that these are correct additions.

  1. EntityContentBase, which extends this class, has its own docblock for processStubRow(). It can now be replaced by {@inheritdoc}. (And yes, Symfony is dropping that, but we haven't adopted it ourselves so out of scope here to change the coding standard.) 🙂
     

  2. Similarly, EntitySearchPage::updateEntity() has its own docblock that can be replaced by {@inheritdoc}.
     

  3. EntityRevisionTest::updateEntity() also has its own docblock, but in that case it's overriding the default behavior (and not calling the parent) so it's justified. However, that implementation's docblock does need the parameter and return docs added.

  4. +++ b/core/modules/migrate/src/Plugin/migrate/destination/Entity.php
    @@ -180,6 +181,29 @@ protected function getEntity(Row $row, array $old_destination_id_values) {
    +   * Updates the entity with the contents of a row.
    +   *
    +   * This method should be implemented in extending classes.
    +   *
    +   * @param \Drupal\Core\Entity\EntityInterface $entity
    +   *   The entity to update.
    +   * @param \Drupal\migrate\Row $row
    +   *   The row object to update from.
    +   */
    +  abstract protected function updateEntity(EntityInterface $entity, Row $row);
    

    It appears that the implementations return $entity, and are expected to do so by callers. So, we should add that return value to the docs.

    The EntityContentBase implementation also has a @throws that is missing here and may be relevant.

  5. +++ b/core/modules/migrate/src/Plugin/migrate/destination/Entity.php
    @@ -180,6 +181,29 @@ protected function getEntity(Row $row, array $old_destination_id_values) {
    +  protected function processStubRow(Row $row) {
    +  }
    

    The closing curly for this should be on the same line.

Thanks for working on this! It's great how many bugs PHPStan is finding in our APIs.

xjm’s picture

Saving credits for the patch and substantive reviews.

mondrake’s picture

Status: Needs work » Needs review
StatusFileSize
new5.49 KB
new4.3 KB

Addressed #12. Thanks!

spokje’s picture

Status: Needs review » Needs work

*cough*
PHPStan errors
*cough*

mondrake’s picture

StatusFileSize
new1.52 KB
new6.66 KB

Yeah, ripple effect of doing #12.4 on a faltering API that was not enforcing typing across its implementations. Maybe #12.4 should not be done here. Anyway, here a patch.

mondrake’s picture

Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Appears that changes requested in #12 have been addressed.

xjm’s picture

Version: 10.0.x-dev » 10.1.x-dev
Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs change record

Thanks @mondrake. I think it's good to include #12.4 here, at least in 10.1.x. Maybe we should add a small change record for it, though.

It looks like the point about the @throws from #12.4 also hasn't been addressed yet, though. Thanks!

xjm’s picture

Come to think of it, this whole issue should get a CR.

mondrake’s picture

Status: Needs work » Needs review

The EntityContentBase implementation also has a @throws that is missing here and may be relevant.

Where? I cannot find it.

this whole issue should get a CR

I do not understand what is changing here that requires a CR. Per #5, the classes that should be extended are EntityConfigBase and EntityContentBase, and they're not changing. If now someone is extending Entity directly without implementing updateEntity(), they would fail anyway.

xjm’s picture

Sorry, it was EntityConfigBase:

   * @throws \LogicException                                                    
   *   Thrown if the destination is for translations and either the "property"  
   *   or "translation" property does not exist.   

Re:

I do not understand what is changing here that requires a CR. Per #5, the classes that should be extended are EntityConfigBase and EntityContentBase, and they're not changing. If now someone is extending Entity directly without implementing updateEntity(), they would fail anyway.

We are adding an API and changing a best practice. That gets a change record. It doesn't have to be a public BC break to get a change record.

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs Review Queue Initiative

For the change record

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.

spokje’s picture

Rerolled 3318888-16.patch on 11.x in MR

spokje’s picture

Status: Needs work » Needs review
Issue tags: -Needs change record

Added draft CR, definitly needs some eyes on that one.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

CR looks good to me, especially since there is nothing for contrib to update.

  • longwave committed 62d7c467 on 11.x
    Issue #3318888 by mondrake, Spokje, smustgrave, xjm, longwave: Fix...
longwave’s picture

Category: Bug report » Task
Status: Reviewed & tested by the community » Fixed
+   * This method should be implemented in extending classes.

This is the definition of an abstract method, so there is probably no need to explicitly say it.

+   * @throws \LogicException
+   *   Thrown for config entities, if the destination is for translations and
+   *   either the "property" or "translation" property does not exist.

This is describing implementation details, which don't relate to this specific base class.

However, I don't think either of these should hold up commit, so let's just get this in. Committed and pushed 62d7c46774 to 11.x (10.2.x), and published the change record. Thanks!

spokje’s picture

This is describing implementation details, which don't relate to this specific base class.

Fully agreed, but couldn't see how to address #12.4 and #22.1

quietone’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.