This docblock bug in \Drupal\Core\Render\ElementInfoManagerInterface::getInfoProperty() makes PHPStan bark whenever a non-string property is in use (Be it in array_merge() or in a array union), like #process, #pre_render, etc.

In custom code I'm now keeping the analyzer happy by introducing a local variable with inline docblock, like /** @var array $pre_renders */. Having to do this is a drag, though. Better of course to just fix the core bug. This method returns mixed, not string.

CommentFileSizeAuthor
#6 infopropreturn-3105095-6.patch649 bytesmikeegoulding

Comments

Eric_A created an issue. See original summary.

cilefen’s picture

Issue tags: +Documentation, +Novice
eric_a’s picture

Issue summary: View changes
eric_a’s picture

Issue summary: View changes

As for the Novice tag added by @cilefen. I'll be happy to review this rather than fix it myself. Anyone?

eric_a’s picture

Issue summary: View changes
mikeegoulding’s picture

StatusFileSize
new649 bytes

Unless I read the issue too fast, I think this is it?

mikeegoulding’s picture

Status: Active » Needs review
eric_a’s picture

Status: Needs review » Reviewed & tested by the community

Unless I read the issue too fast, I think this is it?

@mikeegoulding, thanks, your patch is precisely what I had in mind that is needed here.

eric_a’s picture

Drupal developers delivering PHPStan approved code (level 3 or higher) on the job really profit from this bug fix.

Hooray for no more stupid errors like for example "Cannot assign offset 'blah' to string." Drupal should not be lying to us and static analysis tooling that non-string data is a string. :-)

Easy fix, lots of developer happiness. Living without return type hinting in Drupal becomes a real drag when the doc blocks are incorrect.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 6: infopropreturn-3105095-6.patch, failed testing. View results

ravi.shankar’s picture

Status: Needs work » Reviewed & tested by the community

Unrelated test failures, so making it RTBC as per comment #6.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed 386e98b8c7 to 9.0.x and 59987a5fd1 to 8.9.x and 14ea9e5787 to 8.8.x. Thanks!

Yep we have no idea what type the value is going to be.

Backported to 8.8.x as a docs fix.

  • alexpott committed 386e98b on 9.0.x
    Issue #3105095 by mikeegoulding, Eric_A: ElementInfoManagerInterface::...

  • alexpott committed 59987a5 on 8.9.x
    Issue #3105095 by mikeegoulding, Eric_A: ElementInfoManagerInterface::...

  • alexpott committed 14ea9e5 on 8.8.x
    Issue #3105095 by mikeegoulding, Eric_A: ElementInfoManagerInterface::...

Status: Fixed » Closed (fixed)

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