-
Notifications
You must be signed in to change notification settings - Fork 17
IBX-9727: Fixed strict types of MultiLanguageName
contracts
#599
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
Conversation
return isset($this->names[$this->mainLanguageCode]) | ||
? $this->names[$this->mainLanguageCode] | ||
: reset($this->names); | ||
if (isset($this->mainLanguageCode, $this->names[$this->mainLanguageCode])) { |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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 onmain
instead ofreset
?
Doesn't array_key_first
return an array key, while reset
returns a value?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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>
|
Related PRs:
ContentTypeCreateStruct
building after strict types changes content-forms#92Description:
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 timeFor QA:
Regression build: 🟢 ibexa/commerce#1354