[API] show product price#12279
Conversation
SirDomin
commented
Jan 26, 2021
| Q | A |
|---|---|
| Branch? | master |
| Bug fix? | no |
| New feature? | yes |
| BC breaks? | no |
| Deprecations? | no |
| Related tickets | |
| License | MIT |
5f65eb3 to
042b4a1
Compare
| private function hasProductWithPrice(array $resource, int $price, ?string $productCode = null): bool | ||
| { | ||
| foreach ($resource as $product) { | ||
| if ($productCode && $product['code'] !== $productCode) { |
There was a problem hiding this comment.
Is there any case that $productCode may not exist? Just asking @SirDomin ?
There was a problem hiding this comment.
if you are checking collection, you should specify product code to check wanted product from the list. Otherwise we get only one product, so we dont need to search for it.
There was a problem hiding this comment.
$productCode should have explicit compare to null (to skip casting). Also $productCode check seems to always return false (if product code is equal to null, we will always return false), therefore we can extract this check before the foreach loop. Or even better remove nullable from this value
| private function hasProductWithPrice(array $resource, int $price, ?string $productCode = null): bool | ||
| { | ||
| foreach ($resource as $product) { | ||
| if ($productCode && $product['code'] !== $productCode) { |
There was a problem hiding this comment.
$productCode should have explicit compare to null (to skip casting). Also $productCode check seems to always return false (if product code is equal to null, we will always return false), therefore we can extract this check before the foreach loop. Or even better remove nullable from this value
fac71d2 to
e85ddfb
Compare
276fb1d to
1f86004
Compare
1f86004 to
9075479
Compare
9075479 to
8d04323
Compare
8d04323 to
a2294f9
Compare
lchrusciel
left a comment
There was a problem hiding this comment.
Can we also try to reduce the amount of returned data to the current channel only?
a2294f9 to
10324d0
Compare
10324d0 to
92c5773
Compare
|
Thanks, @SirDomin! 🎉 |