Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PHP 8.1] Fix passing null to non-nullable internal function params #2586

Merged
merged 37 commits into from
Jan 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
8b789de
Fix passing null to str_replace
elidrissidev Jul 13, 2022
74ffa13
Fix passing null to strtolower
elidrissidev Sep 5, 2022
fbc60ea
Fix passing null to strpos
elidrissidev Sep 5, 2022
cc657cc
Fix passing null to preg_match
elidrissidev Sep 5, 2022
9738676
Fix passing null to htmlspecialchars
elidrissidev Sep 5, 2022
ac05634
Fix passing null to trim
elidrissidev Sep 5, 2022
0545c11
Fix passing null to strlen
elidrissidev Sep 5, 2022
f0f726c
Fix passing null to strtotime
elidrissidev Sep 6, 2022
d246a42
Fix passing null to preg_replace
elidrissidev Sep 6, 2022
2cb89c1
Fix passing null to explode
elidrissidev Sep 6, 2022
5eca8b2
Fix passing null to base64_decode
elidrissidev Sep 8, 2022
26bf890
Fix passing null to iconv_strlen
elidrissidev Sep 8, 2022
6af5fad
Fix passing null to preg_split
elidrissidev Sep 9, 2022
bd44998
Fix passing null to sprintf
elidrissidev Sep 10, 2022
dfb08a4
Revert "Fix passing null to preg_split"
elidrissidev Sep 23, 2022
f770e50
Revert "Fix passing null to sprintf"
elidrissidev Oct 9, 2022
a9aafc7
Merge branch '1.9.4.x' into fix/php8.1-compat
sreichel Dec 18, 2022
4779af7
Merge branch '1.9.4.x' into fix/php8.1-compat
sreichel Jan 3, 2023
0ca6922
Merge branch '1.9.4.x' into fix/php8.1-compat
sreichel Jan 3, 2023
2a86ee6
Apply suggestions from code review
sreichel Jan 3, 2023
261147c
Apply suggestions from code review
sreichel Jan 3, 2023
1562edc
Apply suggestions from code review
sreichel Jan 4, 2023
c7bd4bd
Update app/design/frontend/rwd/default/template/persistent/checkout/o…
sreichel Jan 4, 2023
e37c3e6
Merge branch '1.9.4.x' into fix/php8.1-compat
sreichel Jan 4, 2023
3c341a1
Ref #2891
sreichel Jan 5, 2023
92e605a
Ref #2891
sreichel Jan 5, 2023
d2ec4fc
Changed in #2884
sreichel Jan 5, 2023
416c908
Merge branch '1.9.4.x' into fix/php8.1-compat
sreichel Jan 5, 2023
58ce67e
Merge branch '1.9.4.x' into fix/php8.1-compat
sreichel Jan 6, 2023
e728e7f
Merge branch '1.9.4.x' into fix/php8.1-compat
sreichel Jan 6, 2023
e0dfa74
Apply suggestions from code review. ref #2905
sreichel Jan 7, 2023
9c3131f
Fix PHPStan error from ignored error that is no longer present.
colinmollenhour Jan 9, 2023
fce5537
Merge branch '1.9.4.x' into fix/php8.1-compat
colinmollenhour Jan 9, 2023
f891554
Apply suggestions from code review
sreichel Jan 10, 2023
61d276b
Merge branch '1.9.4.x' into fix/php8.1-compat
sreichel Jan 10, 2023
fd9ccc1
Update app/code/core/Mage/Newsletter/Model/Template.php
sreichel Jan 10, 2023
336d43f
Update app/code/core/Mage/SalesRule/Model/Resource/Rule/Collection.php
sreichel Jan 10, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ public function getCurrentStatus()
{
$log = $this->getCustomerLog();
if ($log->getLogoutAt()
|| !$log->getLastVisitAt()
|| strtotime(Varien_Date::now()) - strtotime($log->getLastVisitAt()) > Mage_Log_Model_Visitor::getOnlineMinutesInterval() * 60
) {
return Mage::helper('customer')->__('Offline');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class Mage_Adminhtml_Block_Customer_Online_Grid_Renderer_Url extends Mage_Adminh
*/
public function render(Varien_Object $row)
{
return htmlspecialchars($row->getData($this->getColumn()->getIndex()));
$value = $row->getData($this->getColumn()->getIndex());
return empty($value) ? '' : htmlspecialchars($value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ protected function _toHtml()
$template->setTemplateStyles($this->getRequest()->getParam('styles'));
}
$template->setTemplateStyles(
$this->maliciousCodeFilter($template->getTemplateStyles())
$this->maliciousCodeFilter((string)$template->getTemplateStyles())
);
$template->setTemplateText(
$this->maliciousCodeFilter($template->getTemplateText())
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Adminhtml/Block/Page/Menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ protected function _buildMenuArray(Varien_Simplexml_Element $parent, $path = '',
}

$menuArr['active'] = ($this->getActive() == $path . $childName)
|| (strpos($this->getActive(), $path . $childName . '/') === 0);
|| (strpos((string)$this->getActive(), $path . $childName . '/') === 0);

$menuArr['level'] = $level;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ protected function _getStoreIds()
{
$filterData = $this->getFilterData();
if ($filterData) {
$storeIds = explode(',', $filterData->getData('store_ids'));
$storeIds = explode(',', (string)$filterData->getData('store_ids'));
} else {
$storeIds = [];
}
Expand Down
4 changes: 2 additions & 2 deletions app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ public function setRenderer($renderer)

protected function _getRendererByType()
{
$type = strtolower($this->getType());
$type = strtolower((string)$this->getType());
$renderers = $this->getGrid()->getColumnRenderers();

if (is_array($renderers) && isset($renderers[$type])) {
Expand Down Expand Up @@ -328,7 +328,7 @@ public function setFilter($filterClass)

protected function _getFilterByType()
{
$type = strtolower($this->getType());
$type = strtolower((string)$this->getType());
$filters = $this->getGrid()->getColumnFilters();
if (is_array($filters) && isset($filters[$type])) {
return $filters[$type];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ protected function _getHtmlId()
*/
public function getEscapedValue($index = null)
{
return htmlspecialchars($this->getValue($index));
return htmlspecialchars((string)$this->getValue($index));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,10 @@ protected function _getValue(Varien_Object $row)
}
return '';
}
return $row->getData($this->getColumn()->getIndex());
if ($index = $this->getColumn()->getIndex()) {
return $row->getData($index);
}
return null;
}

/**
Expand Down Expand Up @@ -123,7 +126,7 @@ public function renderHeader()
{
if ($this->getColumn()->getGrid()->getSortable() !== false && $this->getColumn()->getSortable() !== false) {
$className = 'not-sort';
$dir = strtolower($this->getColumn()->getDir());
$dir = strtolower((string)$this->getColumn()->getDir());
$nDir = ($dir == 'asc') ? 'desc' : 'asc';
if ($this->getColumn()->getDir()) {
$className = 'sort-arrow-' . $dir;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ protected function _getRate($row)
if ($rate = $this->getColumn()->getRate()) {
return (float) $rate;
}
if ($rate = $row->getData($this->getColumn()->getRateField())) {
if (($rateField = $this->getColumn()->getRateField()) && ($rate = $row->getData($rateField))) {
return (float) $rate;
}
return 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function render(Varien_Object $row)
if ($this->getColumn()->getTruncate()) {
$truncateLength = $this->getColumn()->getTruncate();
}
$text = Mage::helper('core/string')->truncate(parent::_getValue($row), $truncateLength);
$text = Mage::helper('core/string')->truncate((string)parent::_getValue($row), $truncateLength);
if ($this->getColumn()->getEscape() !== false) {
$text = $this->escapeHtml($text);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ protected function _getRate($row)
if ($rate = $this->getColumn()->getRate()) {
return (float) $rate;
}
if ($rate = $row->getData($this->getColumn()->getRateField())) {
if (($rateField = $this->getColumn()->getRateField()) && ($rate = $row->getData($rateField))) {
return (float) $rate;
}
return 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function _getValue(Varien_Object $row)
if (is_null($format)) {
// If no format and it column not filtered specified return data as is.
$data = parent::_getValue($row);
$string = is_null($data) ? $defaultValue : $data;
$string = $data ?? $defaultValue ?? '';
return $this->escapeHtml($string);
} elseif (preg_match_all($this->_variablePattern, $format, $matches)) {
// Parsing of format string
Expand Down
4 changes: 2 additions & 2 deletions app/code/core/Mage/Catalog/Model/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ public function getPathIds()
{
$ids = $this->getData('path_ids');
if (is_null($ids)) {
$ids = explode('/', $this->getPath());
$ids = explode('/', (string)$this->getPath());
$this->setData('path_ids', $ids);
}
return $ids;
Expand All @@ -728,7 +728,7 @@ public function getPathIds()
public function getLevel()
{
if (!$this->hasLevel()) {
return count(explode('/', $this->getPath())) - 1;
return count(explode('/', (string)$this->getPath())) - 1;
}
return $this->getData('level');
}
Expand Down
4 changes: 2 additions & 2 deletions app/code/core/Mage/Core/Model/Design/Package.php
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ public function getLocaleFileName($file, array $params = [])
/**
* Get skin file url
*
* @param string $file
* @param string|null $file
* @param array $params
* @return string
* @throws Exception
Expand All @@ -528,7 +528,7 @@ public function getSkinUrl($file = null, array $params = [])
Varien_Profiler::start(__METHOD__);

// Prevent reading files outside of the proper directory while still allowing symlinked files
if (strpos($file, '..') !== false) {
if (strpos((string)$file, '..') !== false) {
Mage::log(sprintf('Invalid path requested: %s (params: %s)', $file, json_encode($params)), Zend_Log::ERR);
throw new Exception('Invalid path requested.');
}
Expand Down
8 changes: 4 additions & 4 deletions app/code/core/Mage/Core/Model/Locale.php
Original file line number Diff line number Diff line change
Expand Up @@ -840,16 +840,16 @@ public function isStoreDateInInterval($store, $dateFrom = null, $dateTo = null)
}

$storeTimeStamp = $this->storeTimeStamp($store);
$fromTimeStamp = strtotime($dateFrom);
$toTimeStamp = strtotime($dateTo);
$fromTimeStamp = strtotime((string)$dateFrom);
$toTimeStamp = strtotime((string)$dateTo);
if ($dateTo) {
// fix date YYYY-MM-DD 00:00:00 to YYYY-MM-DD 23:59:59
$toTimeStamp += 86400;
}

$result = false;
if (!is_empty_date($dateFrom) && $storeTimeStamp < $fromTimeStamp) {
} elseif (!is_empty_date($dateTo) && $storeTimeStamp > $toTimeStamp) {
if (!is_empty_date((string)$dateFrom) && $storeTimeStamp < $fromTimeStamp) {
} elseif (!is_empty_date((string)$dateTo) && $storeTimeStamp > $toTimeStamp) {
} else {
$result = true;
}
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Core/Model/Url/Rewrite.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public function loadByTags($tags)
*/
public function hasOption($key)
{
$optArr = explode(',', $this->getOptions());
$optArr = explode(',', (string)$this->getOptions());

return in_array($key, $optArr);
}
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Customer/Model/Address/Abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public function getStreet($line = 0)
if ($line === -1) {
return $street;
} else {
$arr = is_array($street) ? $street : explode("\n", $street);
$arr = is_array($street) ? $street : explode("\n", (string)$street);
if ($line === 0 || $line === null) {
return $arr;
} elseif (isset($arr[$line - 1])) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public function getOptionValues()
$attributeType = $this->getAttributeObject()->getFrontendInput();
$defaultValues = $this->getAttributeObject()->getDefaultValue();
if ($attributeType === 'select' || $attributeType === 'multiselect') {
$defaultValues = explode(',', $defaultValues);
$defaultValues = explode(',', (string)$defaultValues);
} else {
$defaultValues = [];
}
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Eav/Model/Attribute/Data/Multiline.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public function outputValue($format = Mage_Eav_Model_Attribute_Data::OUTPUT_FORM
{
$values = $this->getEntity()->getData($this->getAttribute()->getAttributeCode());
if (!is_array($values)) {
$values = explode("\n", $values);
$values = explode("\n", (string)$values);
}
$values = array_map([$this, '_applyOutputFilter'], $values);
switch ($format) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ class Mage_Eav_Model_Entity_Attribute_Backend_Time_Created extends Mage_Eav_Mode
*/
protected function _getFormat($date)
{
if (is_string($date) && preg_match('#^\d{4,4}-\d{2,2}-\d{2,2}\s\d{2,2}:\d{2,2}:\d{2,2}$#', $date)
|| preg_match('#^\d{4,4}-\d{2,2}-\d{2,2}\w{1,1}\d{2,2}:\d{2,2}:\d{2,2}[+-]\d{2,2}:\d{2,2}$#', $date)
if (is_string($date) && (preg_match('#^\d{4,4}-\d{2,2}-\d{2,2}\s\d{2,2}:\d{2,2}:\d{2,2}$#', $date)
|| preg_match('#^\d{4,4}-\d{2,2}-\d{2,2}\w{1,1}\d{2,2}:\d{2,2}:\d{2,2}[+-]\d{2,2}:\d{2,2}$#', $date))
) {
return 'yyyy-MM-dd HH:mm:ss';
}
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Eav/Model/Entity/Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ public function getValueTablePrefix()
*/
public function getEntityTablePrefix()
{
$tablePrefix = trim($this->_data['value_table_prefix']);
$tablePrefix = trim((string)$this->_data['value_table_prefix']);

if (empty($tablePrefix)) {
$tablePrefix = $this->getEntityTable();
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Widget/Model/Widget/Instance.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ public function getType()
*/
protected function _prepareType()
{
if (strpos($this->_getData('type'), '-') >= 0) {
if (strpos((string)$this->_getData('type'), '-') !== false) {
colinmollenhour marked this conversation as resolved.
Show resolved Hide resolved
$this->setData('type', str_replace('-', '/', $this->_getData('type')));
}
return $this;
Expand Down
2 changes: 1 addition & 1 deletion lib/Varien/Data/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ public function toHtml()
if ($useContainer = $this->getUseContainer()) {
$html .= '<form ' . $this->serialize($this->getHtmlAttributes()) . '>';
$html .= '<div>';
if (strtolower($this->getData('method')) == 'post') {
if (strtolower((string)$this->getData('method')) == 'post') {
$html .= '<input name="form_key" type="hidden" value="' . Mage::getSingleton('core/session')->getFormKey() . '" />';
}
$html .= '</div>';
Expand Down
2 changes: 1 addition & 1 deletion lib/Varien/Data/Form/Element/Abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ public function getEscapedValue($index = null)
if ($filter = $this->getValueFilter()) {
$value = $filter->filter($value);
}
return $this->_escape($value);
return $this->_escape((string)$value);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/Varien/Data/Form/Element/Multiselect.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function getElementHtml()

$value = $this->getValue();
if (!is_array($value)) {
$value = explode(',', $value);
$value = explode(',', (string)$value);
}

if ($values = $this->getValues()) {
Expand Down
5 changes: 0 additions & 5 deletions phpstan.dist.baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -7165,11 +7165,6 @@ parameters:
count: 1
path: app/code/core/Mage/Widget/Block/Adminhtml/Widget/Options.php

-
message: "#^Comparison operation \"\\>\\=\" between int\\<0, max\\>\\|false and 0 is always true\\.$#"
count: 1
path: app/code/core/Mage/Widget/Model/Widget/Instance.php

-
message: "#^If condition is always true\\.$#"
count: 1
Expand Down