Problem/Motivation
Fix
$ignoreErrors[] = [
'message' => '#^Method Drupal\\\\jsonapi\\\\Normalizer\\\\DataNormalizer\\:\\:normalize\\(\\) return type with generic class ArrayObject does not specify its types\\: TKey, TValue$#',
'identifier' => 'missingType.generics',
'count' => 1,
'path' => __DIR__ . '/modules/jsonapi/src/Normalizer/DataNormalizer.php',
];
and similar.
Proposed resolution
Add PHPDoc to document \ArrayDoc, and narrow types where possible.
Remaining tasks
User interface changes
Introduced terminology
API changes
Data model changes
Release notes snippet
| Comment | File | Size | Author |
|---|
Issue fork drupal-3563533
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:
- 3563533-11.x
changes, plain diff MR !15486
- 3563533-fix-phpstan-missingtype.generics
changes, plain diff MR !14118
Comments
Comment #3
mondrakeComment #4
smustgrave commentedshould instances like
Be updated now that the comments are being taken over by core? I mean should the return for each instance only show what it can actually return with a comment that reflects that.
Comment #5
mondrakeRe. #4: these are all normalization methods that more or less inherit from upstream https://github.com/symfony/symfony/blob/8.1/src/Symfony/Component/Serial...
"more or less" because not all of them inherit directly, some are just related and the inheritdoc does not really pick from the class hierarchy. That's why I added explicit comments.
That said, the interface definition is
public function normalize(mixed $data, ?string $format = null, array $context = []): array|string|int|float|bool|\ArrayObject|null;I already narrowed the return type when I was certain of the returned value, and left the original interface return type in the rest of the instances. Please note that type narrowing may have BC concerns.
Comment #6
mondrakeComment #7
smustgrave commentedBased on #5 believe this is probably good. Don't want to get into the weeds.
Comment #8
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #9
nod_local blip
Comment #11
amateescu commentedCommitted 3659d1b and pushed to main. Thanks!
We'll need a 11.x MR for backporting.
Comment #13
mondrakeComment #15
mondrake11.x port
Comment #16
amateescu commentedCommitted ca9f9be and pushed to 11.x. Thanks!
Comment #20
idebr commentedThis broke HAL's \Drupal\hal\Normalizer\FieldNormalizer and subsequently webform tests: https://git.drupalcode.org/issue/webform-3550117/-/pipelines/797824/test...
Comment #22
godotislateConsulted with other release managers @catch and @xjm and noting here that the return type changes are allowed for Drupal 11.4.0, because normalizers are tagged services and not considered public API per Drupal core's backwards compatibility policy.
For visibility, I have published a CR documenting the changes: https://www.drupal.org/node/3588047
Comment #23
tobiasb@godotislate
There is also another CR.
https://www.drupal.org/node/3588046
The CR is now a draft again.