Problem/Motivation

`MessengerInterface::deleteAll()` has an incorrect return type in its docblock.

It currently documents a flat array of messages, matching `messagesByType($type)`, but the implementation returns all messages grouped by message type, matching `MessengerInterface::all()`.

Steps to reproduce

Proposed resolution

Update the @return docblock for MessengerInterface::deleteAll() to document the nested array structure returned by the implementation.

Remaining tasks

- Review the merge request.

User interface changes

Introduced terminology

API changes

The documented return type for `MessengerInterface::deleteAll()` is corrected from a flat array to an array grouped by message type.

Data model changes

None

Release notes snippet

None

Issue fork drupal-3593122

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

nicxvan created an issue. See original summary.

nicxvan’s picture

Issue tags: +Novice

farzana.farook made their first commit to this issue’s fork.

avinash.jha made their first commit to this issue’s fork.

avinash.jha’s picture

Assigned: Unassigned » avinash.jha
Status: Active » Needs review

Fixed the @return docblock for deleteAll() — changed from string[]|MarkupInterface[] to string[][]|MarkupInterface[][] to match ::all(),

Please review and let me know if anything more required

avinash.jha’s picture

Assigned: avinash.jha » Unassigned
smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs issue summary update

Since this is a novice tagged task may be good practice to make sure the summary is updated too.

@avinash.jha mind expanding on how you came up with that one please?

Thanks.

avinash.jha’s picture

Hi @smustgrave

I followed these steps to determine the correct change:

1. The issue description notes: *"It should be the same as ::all() but it is the same as messagesByType($type);"*
2. I checked the implementation in `Messenger::deleteAll()`, which returns `$this->flashBag->clear()`.
3. Looking at Symfony's `FlashBag` class, the `clear()` method clears all flash messages and returns them. Internally, this returns the entire `$this->flashes` array (which is grouped by message type, e.g. `['status' => [...], 'warning' => [...], 'error' => [...]]`).
4. This is the exact same structure returned by `peekAll()` (which is called by `Messenger::all()`).
5. Since the original docblock for `deleteAll()` incorrectly documented a flat array (`string[]|MarkupInterface[]`), I corrected it to a nested array (`string[][]|MarkupInterface[][]`) to match the actual implementation and align it with `::all()`.

brandonlira’s picture

Issue summary: View changes
Status: Needs work » Needs review
brandonlira’s picture

Updated the issue summary with the problem, proposed resolution, remaining tasks, and API changes.

The MR is still mergeable and the pipeline is passing. Moving back to Needs review.

smustgrave’s picture

Status: Needs review » Needs work

Not sure the original purpose was to copy word for word the description from all(). Think that needs to be looked at.

brandonlira’s picture

Issue summary: View changes
brandonlira’s picture

Status: Needs work » Needs review

Hi @smustgrave,

Updated the MR to avoid copying the ::all() return description word for word.

The deleteAll() docblock now keeps the corrected nested return type, but describes the returned values as deleted messages grouped by message type.

The branch was also rebased against the latest main, and the pipeline is passing now.

Moving back to Needs review.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs issue summary update

Reads much better, thanks!

larowlan’s picture

Status: Reviewed & tested by the community » Needs review

Left a comment on the MR about a further improvement - don't make that change yet until we get consensus here - thoughts folks?

smustgrave’s picture

If we do do we update all() too?

larowlan’s picture

Would make sense if we agree with the approach

dcam’s picture

+1 for using the array shape. We're using shapes more and more lately. With those in place we can simplify the return type descriptions too, removing the explanations that specify what the message types are. They become part of the function definition.

smustgrave’s picture

Status: Needs review » Needs work

That’s 3 let’s do it!

brandonlira’s picture

Status: Needs work » Needs review

Updated the MR as suggested.

Both ::all() and ::deleteAll() now use the array shape return type, and the branch was rebased against latest main.

Thanks!

dcam’s picture

Status: Needs review » Reviewed & tested by the community

This looks correct to me, thanks for working on it!

  • catch committed 49e34549 on main
    task: #3593122 MessengerInterface::deleteAll has the wrong return type...

  • catch committed 86425d5e on 11.x
    task: #3593122 MessengerInterface::deleteAll has the wrong return type...
catch’s picture

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

Committed/pushed to main and 11.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.

Status: Fixed » Closed (fixed)

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