Skip to content

Commit f1e92c8

Browse files
committed
Merge remote-tracking branch 'anzin/php8.1-compatibility/fix-unit-tests-to-be-comptaible-with-php8.1' into platform-health
2 parents 7912858 + 07ee647 commit f1e92c8

File tree

19 files changed

+77
-30
lines changed

19 files changed

+77
-30
lines changed

app/code/Magento/Backend/Block/Widget/Grid/Column.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ class Column extends Widget
103103
protected $_isGrouped = false;
104104

105105
/**
106+
* Set property is grouped.
107+
*
106108
* @return void
107109
*/
108110
public function _construct()
@@ -169,7 +171,8 @@ public function getHtmlProperty()
169171
}
170172

171173
/**
172-
* Get Header html
174+
* This method get Header html.
175+
*
173176
* @return string
174177
*/
175178
public function getHeaderHtml()
@@ -222,7 +225,8 @@ public function setSortable($value)
222225
}
223226

224227
/**
225-
* Get header css class name
228+
* Get header css class name.
229+
*
226230
* @return string
227231
*/
228232
public function getHeaderCssClass()
@@ -234,6 +238,8 @@ public function getHeaderCssClass()
234238
}
235239

236240
/**
241+
* This method check if is sortable.
242+
*
237243
* @return bool
238244
* @SuppressWarnings(PHPMD.BooleanGetMethodName)
239245
*/
@@ -256,6 +262,7 @@ public function addHeaderCssClass($className)
256262

257263
/**
258264
* Get header class names
265+
*
259266
* @return string
260267
*/
261268
public function getHeaderHtmlProperty()
@@ -291,6 +298,7 @@ public function getRowField(\Magento\Framework\DataObject $row)
291298
$frameCallback = $this->getFrameCallback();
292299
if (is_array($frameCallback)) {
293300
$this->validateFrameCallback($frameCallback);
301+
//phpcs:ignore Magento2.Functions.DiscouragedFunction
294302
$renderedValue = call_user_func($frameCallback, $renderedValue, $row, $this, false);
295303
}
296304

@@ -334,6 +342,7 @@ public function getRowFieldExport(\Magento\Framework\DataObject $row)
334342
$frameCallback = $this->getFrameCallback();
335343
if (is_array($frameCallback)) {
336344
$this->validateFrameCallback($frameCallback);
345+
//phpcs:ignore Magento2.Functions.DiscouragedFunction
337346
$renderedValue = call_user_func($frameCallback, $renderedValue, $row, $this, true);
338347
}
339348

@@ -412,7 +421,7 @@ public function setRendererType($type, $className)
412421
*/
413422
protected function _getRendererByType()
414423
{
415-
$type = strtolower($this->getType());
424+
$type = strtolower((string) $this->getType());
416425
$rendererClass = isset(
417426
$this->_rendererTypes[$type]
418427
) ? $this->_rendererTypes[$type] : $this->_rendererTypes['default'];
@@ -469,7 +478,7 @@ public function setFilterType($type, $className)
469478
*/
470479
protected function _getFilterByType()
471480
{
472-
$type = $this->getFilterType() ? strtolower($this->getFilterType()) : strtolower($this->getType());
481+
$type = $this->getFilterType() ? strtolower($this->getFilterType()) : strtolower((string) $this->getType());
473482
$filterClass = isset($this->_filterTypes[$type]) ? $this->_filterTypes[$type] : $this->_filterTypes['default'];
474483

475484
return $filterClass;

app/code/Magento/Backend/Block/Widget/Grid/Column/Filter/Date.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ protected function _convertDate($date)
233233
\IntlDateFormatter::NONE,
234234
$adminTimeZone
235235
);
236-
$simpleRes = new \DateTime(null, $adminTimeZone);
236+
$simpleRes = new \DateTime('now', $adminTimeZone);
237237
$simpleRes->setTimestamp($formatter->parse($date));
238238
$simpleRes->setTime(0, 0, 0);
239239
$simpleRes->setTimezone(new \DateTimeZone('UTC'));

app/code/Magento/Backend/Block/Widget/Grid/Column/Renderer/Concat.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,12 @@ public function render(\Magento\Framework\DataObject $row)
3030
&& is_callable([$row, $method])
3131
&& substr_compare('get', $method, 1, 3) !== 0
3232
) {
33+
//phpcs:ignore Magento2.Functions.DiscouragedFunction
3334
$data = call_user_func([$row, $method]);
3435
} else {
3536
$data = $row->getData($method);
3637
}
37-
if (strlen($data) > 0) {
38+
if (strlen((string) $data) > 0) {
3839
$dataArr[] = $data;
3940
}
4041
}

app/code/Magento/Bundle/Model/Option/Validator.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ public function __construct(NotEmptyFactory $notEmptyFactory)
2626
}
2727

2828
/**
29+
* This method check is valid value.
30+
*
2931
* @param \Magento\Bundle\Model\Option $value
32+
*
3033
* @return boolean
3134
* @throws Zend_Validate_Exception If validation of $value is impossible
3235
*/
@@ -38,10 +41,12 @@ public function isValid($value)
3841
}
3942

4043
/**
44+
* This method validate required fields.
45+
*
4146
* @param \Magento\Bundle\Model\Option $value
47+
*
4248
* @return void
43-
* @throws Zend_Validate_Exception
44-
* @throws \Exception
49+
* @throws \Exception|Zend_Validate_Exception
4550
*/
4651
protected function validateRequiredFields($value)
4752
{
@@ -51,7 +56,7 @@ protected function validateRequiredFields($value)
5156
'type' => $value->getType()
5257
];
5358
foreach ($requiredFields as $requiredField => $requiredValue) {
54-
if (!$this->notEmpty->isValid(trim($requiredValue))) {
59+
if (!$this->notEmpty->isValid(trim((string) $requiredValue))) {
5560
$messages[$requiredField] =
5661
__('"%fieldName" is required. Enter and try again.', ['fieldName' => $requiredField]);
5762
}

app/code/Magento/Paypal/Model/Express.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -843,7 +843,7 @@ protected function _isTransactionExpired(Transaction $transaction, $period)
843843
$transactionClosingDate->setTime(11, 49, 00);
844844
$transactionClosingDate->modify('+' . $period . ' days');
845845

846-
$currentTime = new \DateTime(null, new \DateTimeZone('US/Pacific'));
846+
$currentTime = new \DateTime('now', new \DateTimeZone('US/Pacific'));
847847

848848
if ($currentTime > $transactionClosingDate) {
849849
return true;

app/code/Magento/Reports/Model/ResourceModel/Order/Collection.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ protected function _getRangeExpression($range)
352352
protected function _getRangeExpressionForAttribute($range, $attribute)
353353
{
354354
$expression = $this->_getRangeExpression($range);
355-
return str_replace('{{attribute}}', $this->getConnection()->quoteIdentifier($attribute), $expression);
355+
return str_replace('{{attribute}}', $this->getConnection()->quoteIdentifier($attribute), (string) $expression);
356356
}
357357

358358
/**
@@ -369,7 +369,7 @@ protected function _getTZRangeOffsetExpression($range, $attribute, $from = null,
369369
return str_replace(
370370
'{{attribute}}',
371371
$this->_reportOrderFactory->create()->getStoreTZOffsetQuery($this->getMainTable(), $attribute, $from, $to),
372-
$this->_getRangeExpression($range)
372+
(string) $this->_getRangeExpression($range)
373373
);
374374
}
375375

app/code/Magento/Reports/Test/Unit/Model/ResourceModel/Order/CollectionTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,11 @@ public function testPrepareSummary($useAggregatedData, $mainTable, $isFilter, $g
261261
->expects($getIfNullSqlResult)
262262
->method('getIfNullSql');
263263

264+
$this->connectionMock->expects($this->once())
265+
->method('getDateFormatSql')
266+
->with('{{attribute}}', '%Y-%m')
267+
->willReturn(new \Zend_Db_Expr('DATE_FORMAT(%2021-%10, %Y-%m)'));
268+
264269
$this->collection->prepareSummary($range, $customStart, $customEnd, $isFilter);
265270
}
266271

app/code/Magento/Rule/Model/Condition/Product/AbstractProduct.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ public function validate(\Magento\Framework\Model\AbstractModel $model)
546546
$attr = $model->getResource()->getAttribute($attrCode);
547547

548548
if ($attr && $attr->getBackendType() == 'datetime' && !is_int($this->getValue())) {
549-
$this->setValue(strtotime($this->getValue()));
549+
$this->setValue(strtotime((string) $this->getValue()));
550550
$value = strtotime($model->getData($attrCode));
551551
return $this->validateAttribute($value);
552552
}

app/code/Magento/Rule/Model/Condition/Sql/Builder.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,15 +173,21 @@ protected function _getMappedSqlCondition(
173173
) {
174174
$sql = str_replace(
175175
':field',
176-
$this->_connection->getIfNullSql($this->_connection->quoteIdentifier($argument), $defaultValue),
176+
(string) $this->_connection->getIfNullSql(
177+
$this->_connection->quoteIdentifier($argument),
178+
$defaultValue
179+
),
177180
$this->stringConditionOperatorMap[$conditionOperator]
178181
);
179182
$bindValue = $condition->getBindArgumentValue();
180183
$expression = $value . $this->_connection->quoteInto($sql, "%$bindValue%");
181184
} else {
182185
$sql = str_replace(
183186
':field',
184-
$this->_connection->getIfNullSql($this->_connection->quoteIdentifier($argument), $defaultValue),
187+
(string) $this->_connection->getIfNullSql(
188+
$this->_connection->quoteIdentifier($argument),
189+
$defaultValue
190+
),
185191
$this->_conditionOperatorMap[$conditionOperator]
186192
);
187193
$bindValue = $condition->getBindArgumentValue();

app/code/Magento/Shipping/Model/Simplexml/Element.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
67
namespace Magento\Shipping\Model\Simplexml;
78

89
/**
@@ -21,9 +22,7 @@ class Element extends \Magento\Framework\Simplexml\Element
2122
*/
2223
public function addAttribute($name, $value = null, $namespace = null)
2324
{
24-
if ($value !== null) {
25-
$value = $this->xmlentities($value);
26-
}
25+
$value = $value !== null ? $this->xmlentities($value) : '';
2726
parent::addAttribute($name, $value, $namespace);
2827
}
2928

0 commit comments

Comments
 (0)