Problem/Motivation

Fix

$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\Core\\\\Config\\\\Schema\\\\ArrayElement\\:\\:getIterator\\(\\) return type with generic class ArrayIterator does not specify its types\\: TKey, TValue$#',
	'identifier' => 'missingType.generics',
	'count' => 1,
	'path' => __DIR__ . '/lib/Drupal/Core/Config/Schema/ArrayElement.php',
];

and similar.

Proposed resolution

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Issue fork drupal-3563727

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
dcam’s picture

In composer/Plugin/Scaffold/Operations/ScaffoldFileCollection.php, the array shape is applied to the docblock of the property used in the iterator. But the same isn't done in core/lib/Drupal/Core/Config/Schema/ArrayElement.php, which returns the ArrayElement->elements. Is this an intentional omission or was it missed? I noticed the same thing in core/lib/Drupal/Core/Template/Attribute.php with the storage property.

mondrake’s picture

Status: Needs review » Needs work

Thanks @dcam. #4 is a miss, will address it.

mondrake’s picture

Status: Needs work » Needs review

fixed #4

dcam’s picture

Status: Needs review » Reviewed & tested by the community

Thank you for considering my feedback. These changes look good to me.

mondrake’s picture

I think as a follow up we should file an issue to mglaman/phpstan-drupal to do what @mglaman was suggesting in #3496417-7: Fix PHPStan missingType.generics for FieldItemListInterface not specifying its type

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

  • longwave committed 8b702713 on 11.3.x
    docs: #3563727 Fix PHPStan missingType.generics for \ArrayIterator not...

  • longwave committed 3fe359f6 on 11.x
    docs: #3563727 Fix PHPStan missingType.generics for \ArrayIterator not...
longwave’s picture

Version: main » 11.3.x-dev
Status: Reviewed & tested by the community » Fixed

Backported down to 11.3.x as a documentation fix. Doesn't apply cleanly to 10.6.x, not sure it's worth it.

Committed and pushed b419ec85d91 to main and 3fe359f6f17 to 11.x and 8b702713b46 to 11.3.x. Thanks!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

  • longwave committed b419ec85 on main
    docs: #3563727 Fix PHPStan missingType.generics for \ArrayIterator not...

Status: Fixed » Closed (fixed)

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

acbramley’s picture

I believe this had a side effect of throwing phpstan errors that don't seem to be correct (i.e the code works fine). Upgrading from 11.3.2 to 11.3.3 started throwing a bunch of errors like Drupal\Core\Template\Attribute does not accept string.

The offending code was doing something like this:

$attributes = new Attribute();
$attributes['data-short-title'] = 'foo';
$attributes['class'] = ['is-excluded'];

Swapping to $attributes->setAttribute fixed it for now.