Skip to content

Conversation

@mstrelan
Copy link

Running phpstan against core with checkFunctionArgumentTypes: true results in several instances of this error:

Parameter #1 $offset of method Drupal\Core\TypedData\Plugin\DataType\ItemList<Drupal\Core\Field\FieldItemInterface>::offsetExists() expects int, Drupal\Core\TypedData\Plugin\DataType\TKey given.

Mostly in ComputedItemListTrait, but also once in CommentFieldItemList.

This is because \Drupal\Core\TypedData\ListInterface extends \ArrayAccess which defines TKey as the param type for $offset. We need to define what TKey is in the ListInterface stub.

Steps to reproduce

  1. Checkout drupal core 11.x
  2. composer install
  3. Add checkFunctionArgumentTypes: true to this to core/phpstan.neon.dist
  4. ./vendor/bin/phpstan analyse -c core/phpstan.neon.dist --error-format=raw | grep -F 'Drupal\Core\TypedData\Plugin\DataType\ItemList'

@mglaman
Copy link
Owner

mglaman commented Oct 16, 2025

Did this fix the issue for you? Because I don't think the problem is the generic template here but someplace else

@mglaman
Copy link
Owner

mglaman commented Oct 16, 2025

@mstrelan can you test my commit?

@mstrelan
Copy link
Author

@mglaman that didn't work, tested a few times clearing phpstan cache in between

No patches: 447 errors
My patch: 439 errors
Your patch: 447 errors

These are the additional errors:

core/lib/Drupal/Core/TypedData/ComputedItemListTrait.php (in context of class Drupal\content_moderation\Plugin\Field\ModerationStateFieldItemList):123:Parameter #1 $offset of method Drupal\Core\TypedData\Plugin\DataType\ItemList<Drupal\Core\Field\FieldItemInterface>::offsetExists() expects int, Drupal\Core\TypedData\Plugin\DataType\TKey given.
core/lib/Drupal/Core/TypedData/ComputedItemListTrait.php (in context of class Drupal\entity_test\Plugin\Field\ComputedReferenceTestFieldItemList):123:Parameter #1 $offset of method Drupal\Core\TypedData\Plugin\DataType\ItemList<Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem<Drupal\Core\Entity\EntityInterface>>::offsetExists() expects int, Drupal\Core\TypedData\Plugin\DataType\TKey given.
core/lib/Drupal/Core/TypedData/ComputedItemListTrait.php (in context of class Drupal\entity_test\Plugin\Field\ComputedTestBundleFieldItemList):123:Parameter #1 $offset of method Drupal\Core\TypedData\Plugin\DataType\ItemList<Drupal\Core\Field\FieldItemInterface>::offsetExists() expects int, Drupal\Core\TypedData\Plugin\DataType\TKey given.
core/lib/Drupal/Core/TypedData/ComputedItemListTrait.php (in context of class Drupal\entity_test\Plugin\Field\ComputedTestCacheableIntegerItemList):123:Parameter #1 $offset of method Drupal\Core\TypedData\Plugin\DataType\ItemList<Drupal\Core\Field\FieldItemInterface>::offsetExists() expects int, Drupal\Core\TypedData\Plugin\DataType\TKey given.
core/lib/Drupal/Core/TypedData/ComputedItemListTrait.php (in context of class Drupal\entity_test\Plugin\Field\ComputedTestCacheableStringItemList):123:Parameter #1 $offset of method Drupal\Core\TypedData\Plugin\DataType\ItemList<Drupal\Core\Field\FieldItemInterface>::offsetExists() expects int, Drupal\Core\TypedData\Plugin\DataType\TKey given.
core/lib/Drupal/Core/TypedData/ComputedItemListTrait.php (in context of class Drupal\entity_test\Plugin\Field\ComputedTestFieldItemList):123:Parameter #1 $offset of method Drupal\Core\TypedData\Plugin\DataType\ItemList<Drupal\Core\Field\FieldItemInterface>::offsetExists() expects int, Drupal\Core\TypedData\Plugin\DataType\TKey given.
core/lib/Drupal/Core/TypedData/ComputedItemListTrait.php (in context of class Drupal\path\Plugin\Field\FieldType\PathFieldItemList):123:Parameter #1 $offset of method Drupal\Core\TypedData\Plugin\DataType\ItemList<Drupal\Core\Field\FieldItemInterface>::offsetExists() expects int, Drupal\Core\TypedData\Plugin\DataType\TKey given.
core/modules/comment/src/CommentFieldItemList.php:39:Parameter #1 $offset of method Drupal\Core\TypedData\Plugin\DataType\ItemList<Drupal\Core\Field\FieldItemInterface>::offsetExists() expects int, Drupal\Core\TypedData\Plugin\DataType\TKey given.

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.

2 participants