-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Update AttributeRepository.php #9387
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
Fixes a bug in case `$attribute->getOption()` returns NULL when it does not have any options. When NULL is given to `AttributeRepository::getOptionArray`, PHP complains about a TypeError.
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.
Service contract for \Magento\Customer\Api\Data\AttributeMetadataInterface::getOptions
(which is the $attribute
in this case) states that the only possible return type is OptionInterface[]
. It is better to check why is it null
in the specific case and fix it.
@@ -95,12 +95,13 @@ protected function getListForEntity(array $metadata, $entityTypeCode, MetadataMa | |||
if ($entityTypeCode == AddressMetadataInterface::ENTITY_TYPE_ADDRESS) { | |||
$attributeCode = self::BILLING_ADDRESS_PREFIX . $attribute->getAttributeCode(); | |||
} | |||
$attributeOptions = $attribute->getOption(); |
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.
Original code used $attribute->getOptions()
did you mean it?
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.
No, don't know how it got there
$attributes[$attributeCode] = [ | ||
AttributeMetadataInterface::ATTRIBUTE_CODE => $attributeCode, | ||
AttributeMetadataInterface::FRONTEND_INPUT => $attribute->getFrontendInput(), | ||
AttributeMetadataInterface::FRONTEND_LABEL => $attribute->getFrontendLabel(), | ||
AttributeMetadataInterface::BACKEND_TYPE => $attribute->getBackendType(), | ||
AttributeMetadataInterface::OPTIONS => $this->getOptionArray($attribute->getOptions()), | ||
AttributeMetadataInterface::OPTIONS => is_array($attributeOptions) ? $this->getOptionArray($attributeOptions) : [], |
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.
This line is too long. Magento code style standard requires lines to be no longer then 120 characters.
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.
Updated.
@ishakhsuvarov Updated the code with your change requests. |
@redelschaap Please check the general comment as well:
I am not sure this is the most optimal fix at the moment |
I think this fix is optimal, because we have a situation where that method does not return an array of |
@redelschaap Service contract claims that no |
@ishakhsuvarov That's the theory, practice shows otherwise ;). I can't reproduce the bug right now as we're working towards the launch of the website. Where do you suggest this should be fixed? |
@redelschaap I would suggest finding exact case, where it reproduces, and fixing the reason why |
Well in my case an extension was responsible, that I do know. You can't say "it's the extension's fault, they should fix it", when Magento's core makes it possible to leave the |
@redelschaap Closing this PR for now. Please reopen if this issue occurs again with the reproducible steps. We will definitely look for ways to solve the problem. |
Fixes a bug in case
$attribute->getOption()
returns NULL when it does not have any options. When NULL is given toAttributeRepository::getOptionArray
, PHP complains about a TypeError.