Skip to content

Commit

Permalink
[PHP 8.1] Fix passing null to non-nullable internal function params (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
elidrissidev authored Jan 10, 2023
1 parent e7cd88b commit bd0cb12
Show file tree
Hide file tree
Showing 26 changed files with 37 additions and 37 deletions.
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) {
$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

0 comments on commit bd0cb12

Please sign in to comment.