Skip to content

Commit ad3e3cb

Browse files
committed
Fixed php 8.1 deprecations to pass Integration Tests
1 parent 40ceb70 commit ad3e3cb

File tree

12 files changed

+49
-30
lines changed

12 files changed

+49
-30
lines changed

app/code/Magento/Catalog/Helper/Product/View.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,9 @@ private function preparePageMetadata(ResultPage $resultPage, $product)
141141
if ($description) {
142142
$pageConfig->setDescription($description);
143143
} else {
144-
$pageConfig->setDescription($this->string->substr(strip_tags($product->getDescription()), 0, 255));
144+
$productDescription = is_string($product->getDescription()) ?
145+
$this->string->substr(strip_tags($product->getDescription()), 0, 255) : '';
146+
$pageConfig->setDescription($productDescription);
145147
}
146148

147149
if ($this->_catalogProduct->canUseCanonicalTag()) {
@@ -184,7 +186,7 @@ public function initProductLayout(ResultPage $resultPage, $product, $params = nu
184186
$pageConfig->setPageLayout($settings->getPageLayout());
185187
}
186188

187-
$urlSafeSku = rawurlencode($product->getSku());
189+
$urlSafeSku = is_string($product->getSku()) ? rawurlencode($product->getSku()) : '';
188190

189191
// Load default page handles and page configurations
190192
if ($params && $params->getBeforeHandles()) {

app/code/Magento/PageCache/Model/System/Config/Backend/Varnish.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ protected function _afterLoad()
5858
$currentValue = $this->getValue();
5959
if (!$currentValue) {
6060
foreach ($data as $field => $value) {
61-
if (strstr($this->getPath(), (string) $field)) {
61+
if (is_string($this->getPath()) && strstr($this->getPath(), (string) $field)) {
6262
$this->setValue($value);
6363
$this->save();
6464
break;

app/code/Magento/ReleaseNotification/Model/Condition/CanViewNotification.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,9 @@ public function isVisible(array $arguments)
8282
$cacheKey = self::$cachePrefix . $userId;
8383
$value = $this->cacheStorage->load($cacheKey);
8484
if ($value === false) {
85-
$value = version_compare(
86-
$this->viewerLogger->get($userId)->getLastViewVersion(),
87-
$this->productMetadata->getVersion(),
88-
'<'
89-
);
85+
$lastViewVersion = $this->viewerLogger->get($userId)->getLastViewVersion() ?: '';
86+
$productMetadataVersion = $this->productMetadata->getVersion() ?: '';
87+
$value = version_compare($lastViewVersion, $productMetadataVersion, '<');
9088
$this->cacheStorage->save(false, $cacheKey);
9189
}
9290
return (bool)$value;

app/code/Magento/Sales/Helper/Guest.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,11 +227,14 @@ private function setGuestViewCookie($cookieValue)
227227
*/
228228
private function loadFromCookie($fromCookie)
229229
{
230+
if (!is_string($fromCookie)) {
231+
throw new InputException(__($this->inputExceptionMessage));
232+
}
230233
// phpcs:ignore Magento2.Functions.DiscouragedFunction
231234
$cookieData = explode(':', base64_decode($fromCookie));
232-
$protectCode = isset($cookieData[0]) ? $cookieData[0] : null;
233-
$incrementId = isset($cookieData[1]) ? $cookieData[1] : null;
234-
if (!empty($protectCode) && !empty($incrementId)) {
235+
$protectCode = $cookieData[0] ?? null;
236+
$incrementId = $cookieData[1] ?? null;
237+
if ($protectCode && $incrementId) {
235238
$order = $this->getOrderRecord($incrementId);
236239
if (hash_equals((string)$order->getProtectCode(), $protectCode)) {
237240
$this->setGuestViewCookie($fromCookie);

dev/tests/integration/testsuite/Magento/Framework/Image/Adapter/InterfaceTest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,12 @@ protected function _getFixture($pattern)
115115
*/
116116
protected function _isFormatSupported($image, $adapter)
117117
{
118+
if (!$image || !file_exists($image)) {
119+
return false;
120+
}
118121
$data = pathinfo($image);
119-
$supportedTypes = $adapter->getSupportedFormats();
120-
return $image && file_exists($image) && in_array(strtolower($data['extension']), $supportedTypes);
122+
123+
return isset($data['extension']) && in_array(strtolower($data['extension']), $adapter->getSupportedFormats());
121124
}
122125

123126
/**

dev/tests/integration/testsuite/Magento/Framework/Translate/InlineTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public function processResponseBodyDataProvider()
119119
$package = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
120120
\Magento\Framework\View\DesignInterface::class
121121
)->getDesignTheme()->getPackageCode();
122-
$expectedText = str_replace('{{design_package}}', $package, $expectedText);
122+
$expectedText = str_replace('{{design_package}}', is_string($package) ? $package : '', $expectedText);
123123
return [
124124
'plain text' => ['text with no translations and tags', 'text with no translations and tags'],
125125
'html string' => [$originalText, $expectedText],

lib/internal/Magento/Framework/DB/Helper/AbstractHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ protected function getConnection()
6363
*/
6464
public function escapeLikeValue($value, $options = [])
6565
{
66-
$value = str_replace('\\', '\\\\', $value);
66+
$value = is_string($value) ? str_replace('\\', '\\\\', $value) : '';
6767

6868
$replaceFrom = [];
6969
$replaceTo = [];

lib/internal/Magento/Framework/Filter/StripTags.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ public function __construct(\Magento\Framework\Escaper $escaper, $allowableTags
4545
*/
4646
public function filter($value)
4747
{
48-
$result = strip_tags($value, $this->allowableTags);
48+
$result = is_string($value) ? strip_tags($value, $this->allowableTags) : '';
49+
4950
return $this->escape ? $this->escaper->escapeHtml($result, $this->allowableTags) : $result;
5051
}
5152
}

lib/internal/Magento/Framework/Image/Adapter/Gd2.php

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ protected function _reset()
6363
*/
6464
public function open($filename)
6565
{
66-
if (!file_exists($filename)) {
66+
if (!$filename || !file_exists($filename)) {
6767
throw new FileSystemException(
6868
new Phrase('File "%1" does not exist.', [$this->_fileName])
6969
);
@@ -267,7 +267,7 @@ private function _getCallback($callbackType, $fileType = null, $unsupportedText
267267
* Returns a color identifier.
268268
*
269269
* @param resource &$imageResourceTo
270-
* @return int
270+
* @return void
271271
* @throws \InvalidArgumentException
272272
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
273273
*/
@@ -293,8 +293,6 @@ private function _fillBackgroundColor(&$imageResourceTo)
293293
if (!imagesavealpha($imageResourceTo, true)) {
294294
throw new \InvalidArgumentException('Failed to save alpha transparency into PNG image.');
295295
}
296-
297-
return $transparentAlphaColor;
298296
} elseif (false !== $transparentIndex) {
299297
// fill image with indexed non-alpha transparency
300298
$transparentColor = false;
@@ -309,20 +307,23 @@ private function _fillBackgroundColor(&$imageResourceTo)
309307
throw new \InvalidArgumentException('Failed to fill image with transparency.');
310308
}
311309
imagecolortransparent($imageResourceTo, $transparentColor);
312-
return $transparentColor;
313310
}
314311
// phpcs:ignore Magento2.CodeAnalysis.EmptyBlock.DetectedCatch
315312
} catch (\Exception $e) {
316313
// fallback to default background color
317314
}
318315
}
319-
list($r, $g, $b) = $this->_backgroundColor;
320-
$color = imagecolorallocate($imageResourceTo, $r, $g, $b);
321-
if (!imagefill($imageResourceTo, 0, 0, $color)) {
322-
throw new \InvalidArgumentException("Failed to fill image background with color {$r} {$g} {$b}.");
323-
}
316+
list($red, $green, $blue) = $this->_backgroundColor;
324317

325-
return $color;
318+
if ($imageResourceTo && $red && $green && $blue) {
319+
$color = imagecolorallocate($imageResourceTo, $red, $green, $blue);
320+
321+
if (!$color && !imagefill($imageResourceTo, 0, 0, $color)) {
322+
throw new \InvalidArgumentException(
323+
"Failed to fill image background with color {$red} {$green} {$blue}."
324+
);
325+
}
326+
}
326327
}
327328

328329
/**

lib/internal/Magento/Framework/Serialize/Serializer/Json.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,13 @@ public function serialize($data)
3434
*/
3535
public function unserialize($string)
3636
{
37+
if ($string === null) {
38+
throw new \InvalidArgumentException(
39+
sprintf('Invalid parameter: string must be a string type, null given.')
40+
);
41+
}
3742
$result = json_decode($string, true);
43+
3844
if (json_last_error() !== JSON_ERROR_NONE) {
3945
throw new \InvalidArgumentException("Unable to unserialize value. Error: " . json_last_error_msg());
4046
}

0 commit comments

Comments
 (0)