+
Skip to content

Conversation

alongosz
Copy link
Member

@alongosz alongosz commented Jun 17, 2025

🎫 Issue IBX-9727

Related PRs:

Description:

As uncovered by content-forms#92 CI, we need to ensure in MultiLanguageNameTrait::getName that $this->mainLanguageCode is initialized before accessing that.

This presents a good opportunity to add strict types to the MultiLanguageName contracts tied to it.

Note: The trait itself was not a very good design (e.g., references mainLanguageCode defined elsewhere), but let's tackle one issue at a time

For QA:

Regression build: 🟢 ibexa/commerce#1354

return isset($this->names[$this->mainLanguageCode])
? $this->names[$this->mainLanguageCode]
: reset($this->names);
if (isset($this->mainLanguageCode, $this->names[$this->mainLanguageCode])) {
Copy link
Member Author

@alongosz alongosz Jun 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note

The content-forms bug is fixed by adding $this->mainLanguage to the isset list prior using it

if (isset($this->mainLanguageCode, $this->names[$this->mainLanguageCode])) {
return $this->names[$this->mainLanguageCode];
}
$defaultName = reset($this->names);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Philosophical question - wouldn't it be better to use array_key_first here since it's PHP 8.3 on main instead of reset?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Philosophical question - wouldn't it be better to use array_key_first here since it's PHP 8.3 on main instead of reset?

Doesn't array_key_first return an array key, while reset returns a value?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it does, but we can use this key to get an item from this array instead of reset which alters the pointer

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it does, but we can use this key to get an item from this array instead of reset which alters the pointer

@barw4 So, something like 570f2c0?

I don't mind it that much. We have there though implicit $this->names[null] to $this->names[''] cast in case if the array is empty. However at least I don't need to deal with false value :D

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, that's what I had in mind ❤️

Co-Authored-By: Bartek Wajda <barw4@users.noreply.github.com>
Copy link

@alongosz alongosz merged commit 898dfa8 into main Jun 18, 2025
16 checks passed
@alongosz alongosz deleted the ibx-9727-fix-fdef-main-lang-trait branch June 18, 2025 08:32
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.

6 participants

点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载