Fixed #13319 , Incorrect method return value in \Magento\Shipping\Model\Carrier\AbstractCarrier::getTotalNumOfBoxes() #20898
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.
Fixed #13319 , Incorrect method return value in \Magento\Shipping\Model\Carrier\AbstractCarrier::getTotalNumOfBoxes()
added type casting and updated function comment..
Please see the method
getTotalNumOfBoxes()
in\Magento\Shipping\Model\Carrier\AbstractCarrier
: https://github.com/magento/magento2/blob/2.2.2/app/code/Magento/Shipping/Model/Carrier/AbstractCarrier.php#L512-L531Incoming
$weight
parameter is not checked to be integer. Moreover, even if it is, you can still get a float result when$weight > $maxPackageWeight
since these are both arbitrary numbers.This method is a member of
AbstractCarrier
class commonly used for 3-rd party implementations of the Shipmen Carrier SPI and might be used by 3rd-party developers in their modules.In order to apply proper validation and\or rounding around the method's return results, it would be helpful to see the actual return value in PHPDocs which are commonly used by IDEs when providing hints, for example here: http://take.ms/9dnaD
Additionally, the method name is severely misleading: it implies the method is a getter, however it can modify object's internal state. Moreover, the value returned is in fact what seems to be an average weight of a box, not "Total number of boxes" as one might assume.
Backward Compatibility: Please note that Magento's USPS implementation expects float return value, implying internal knowledge of the method: https://github.com/magento/magento2/blob/2.2.2/app/code/Magento/Usps/Model/Carrier.php#L341
If any rounding is to be added, it should probably be done via a new extra method, deprecating the old one (if at all)
Preconditions
Steps to reproduce
Expected result
OR proper rounding applied to the
$weight
variable.Actual result
AND no rounding applied to $weight variable
Contribution checklist (*)