fix: array to string conversion#383
Open
ahuininga-orisha wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
See issue EmicoEcommerce/Magento2TweakwiseHyva#91
When the Tweakwise API returns a facet's title as an array instead of a string (malformed or unexpected API response), calling
getName()on aFiltertriggered anArray to string conversionPHP warning. This could happen for any facet — including Tweakwise-only facets that have no corresponding Magento EAV attribute — and would produce a PHP warning on the storefront.The suggested fix in the issue report patched
Filter::getName(), but that treats the symptom rather than the cause.SettingsType::getTitle()is declared to returnstringand is called in multiple places — fixing the data contract at the source protects all callers.@method string getTitle()magic docblock inSettingsTypewith an explicitgetTitle(): stringmethod, consistent with how all other getters in that class are implemented (e.g.getUrlKey(),getSelectionType()).(string)cast inFilter::getName()sincegetTitle()is now guaranteed to return a string.How to test
Scenario 1 — Normal API response (regression check)
var/log/exception.log,var/log/system.log).Scenario 2 — Malformed API response with array title
titlefield is an array (e.g.["Color"]instead of"Color").Array to string conversionPHP warning is triggered.