Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4.4] Remove unsed variable messages from enqueue messages #42948

Open
wants to merge 4 commits into
base: 4.4-dev
Choose a base branch
from

Conversation

chmst
Copy link
Contributor

@chmst chmst commented Mar 4, 2024

Pull Request for Issue # .

Summary of Changes

As title says, there is an unused variable.

Testing Instructions

Test different situations where messages are sent and also enqueued, like here
grafik

All messages must be the same before and after patch

@laoneo
Copy link
Member

laoneo commented Mar 4, 2024

This should be properly tested as the function getMessageQueue initializes $this->messageQueue which is used later down. I don't think so we can remove that line. Perhaps the returned $messages variable should be used instead of $this->messageQueue.

@laoneo laoneo added the Updates Requested Indicates that this pull request needs an update from the author and should not be tested. label Mar 4, 2024
@chmst
Copy link
Contributor Author

chmst commented Mar 4, 2024

Then we let it as is. Just looks weird in the IDE.

@chmst chmst closed this Mar 4, 2024
@laoneo
Copy link
Member

laoneo commented Mar 4, 2024

What you can remove is $messages = as the $messages variable is not used anywhere.

@chmst
Copy link
Contributor Author

chmst commented Mar 4, 2024

shouldn't it be
$this->messageQueue = $this->getMessageQueue()

@joomdonation
Copy link
Contributor

Better remove the line as you did here, and replace next line with

if (!\in_array($message, $this->getMessageQueue())) {
	// Enqueue the message.
	$this->messageQueue[] = $message;
}

$this->getMessageQueue() needs to be called here instead of just $this->messageQueue to avoid the messages queued before redirecting to new page (for example, after saving an article, we will be redirected to articles management page, the messages queued before during save process are still being displayed)

@chmst chmst reopened this Mar 4, 2024
@Fedik
Copy link
Member

Fedik commented Mar 4, 2024

@joomdonation I think with this changes we losing the context,
why it $this->getMessageQueue() and not just $this->messageQueue.

I would suggest to keep that comment and the logic. Kind of:

// For empty queue, if messages exists in the session, enqueue them first.
$this->getMessageQueue();

if (!\in_array($message, $this->messageQueue)) {
   // Enqueue the message.
  $this->messageQueue[] = $message;
}

@joomdonation
Copy link
Contributor

@chmst @Fedik That also works, but it is also a bit confusing when calling method returns data but we do not use that returned data for any thing. Honestly, I don't know what's better, but I would also not complain if your code is used. The most important thing is get rid of unused variable so that the code is not being removed by mistake in the future.

@chmst
Copy link
Contributor Author

chmst commented Mar 4, 2024

Agree with @joomdonation
For me the comment itself is confusing and clearer to have only the code.

@Fedik
Copy link
Member

Fedik commented Mar 4, 2024

For me the comment itself is confusing and clearer to have only the code.

The problem, that in future, someone may refactor that code, and just replace
if (!\in_array($message, $this->getMessageQueue())) {
back to
if (!\in_array($message, $this->messageQueue)) {

Because, why not?

But it is important to call $this->getMessageQueue() to load previous messages from session.
The comment is important, even if it confusing.

It can stay as you made, but then please add a comment with explanation.

@chmst
Copy link
Contributor Author

chmst commented Mar 4, 2024

@Fedik what about that comment?

@Fedik
Copy link
Member

Fedik commented Mar 4, 2024

Good enough, thanks 😉

@laoneo laoneo removed the Updates Requested Indicates that this pull request needs an update from the author and should not be tested. label Mar 4, 2024
@HLeithner
Copy link
Member

I wouldn't do this in 4.4 and move it 5.2 since it doesn't solve a bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants