Skip to content
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
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 @@ -92,7 +92,7 @@ public function getValue($key, $default = '', $defaultNew = null)
}

$value = $this->getData($key);
return $this->escapeHtml($value !== null && strlen($value) > 0 ? $value : $default);
return $this->escapeHtml($value !== null && (string) $value !== '' ? $value : $default);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What of them rector/phpstan or pslam is against !empty($value)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Guess it includes multiple checks that makes it less readable.

}

/**
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Adminhtml/Block/Widget/Grid.php
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ protected function _setFilterValues($data)
foreach (array_keys($data) as $columnId) {
$column = $this->getColumn($columnId);
if ($column instanceof Mage_Adminhtml_Block_Widget_Grid_Column
&& (!empty($data[$columnId]) || strlen($data[$columnId]) > 0)
&& (!empty($data[$columnId]) || (string) $data[$columnId] !== '')
&& $column->getFilter()
) {
$column->getFilter()->setValue($data[$columnId]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ public function getValue($index = null)
}

$value = $this->getData('value');
if ((isset($value['from']) && strlen($value['from']) > 0)
|| (isset($value['to']) && strlen($value['to']) > 0)
if ((isset($value['from']) && (string) $value['from'] !== '')
|| (isset($value['to']) && (string) $value['to'] !== '')
) {
return $value;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ public function getValue($index = null)
}

$value = $this->getData('value');
if ((isset($value['from']) && strlen($value['from']) > 0)
|| (isset($value['to']) && strlen($value['to']) > 0)
if ((isset($value['from']) && (string) $value['from'] !== '')
|| (isset($value['to']) && (string) $value['to'] !== '')
) {
return $value;
}
Expand Down
4 changes: 1 addition & 3 deletions app/code/core/Mage/Api2/Model/Renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ public static function factory($acceptTypes)
foreach ($acceptTypes as $type) {
foreach ($adapters as $item) {
$itemType = $item->type;
if ($type == $itemType
|| $type == current(explode('/', $itemType)) . '/*' || $type == '*/*'
) {
if (in_array($type, [$itemType, current(explode('/', $itemType)) . '/*', '*/*'])) {
$adapterPath = $item->model;
break 2;
}
Expand Down
6 changes: 2 additions & 4 deletions app/code/core/Mage/Bundle/Model/Product/Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -849,19 +849,17 @@ public function getOrderOptions($product = null)
*/
public function shakeSelections($a, $b)
{
$aPosition = [
return [
$a->getOption()->getPosition(),
$a->getOptionId(),
$a->getPosition(),
$a->getSelectionId(),
];
$bPosition = [
] <=> [
$b->getOption()->getPosition(),
$b->getOptionId(),
$b->getPosition(),
$b->getSelectionId(),
];
return $aPosition <=> $bPosition;
}

/**
Expand Down
19 changes: 11 additions & 8 deletions app/code/core/Mage/Catalog/Block/Product/View/Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,17 +127,20 @@ public function hasOptions()
*
* @param Mage_Catalog_Model_Product_Option_Value|Mage_Catalog_Model_Product_Option $option
* @return array
* @throws Mage_Core_Model_Store_Exception
*/
protected function _getPriceConfiguration($option)
{
$data = [];
$data['price'] = Mage::helper('core')->currency($option->getPrice(true), false, false);
$data['oldPrice'] = Mage::helper('core')->currency($option->getPrice(false), false, false);
$data['priceValue'] = $option->getPrice(false);
$data['type'] = $option->getPriceType();
$data['excludeTax'] = $price = Mage::helper('tax')->getPrice($option->getProduct(), $data['price'], false);
$data['includeTax'] = $price = Mage::helper('tax')->getPrice($option->getProduct(), $data['price'], true);
return $data;
$price = Mage::helper('core')->currency($option->getPrice(true), false, false);

return [
'price' => $price,
'oldPrice' => Mage::helper('core')->currency($option->getPrice(false), false, false),
'priceValue' => $option->getPrice(false),
'type' => $option->getPriceType(),
'excludeTax' => Mage::helper('tax')->getPrice($option->getProduct(), $price, false),
'includeTax' => Mage::helper('tax')->getPrice($option->getProduct(), $price, true),
];
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ protected function _binarySearch($value, $limits = null)
}

$separator = floor(($limits[0] + $limits[1]) / 2);
if ($this->_prices[$separator] < $value) {
if ($this->_prices[(string) $separator] < $value) {
$limits[0] = $separator + 1;
} else {
$limits[1] = $separator;
Expand Down Expand Up @@ -486,7 +486,7 @@ protected function _findRoundPrice($lowerPrice, $upperPrice, $returnEmpty = true
if ($roundPrices) {
$index = round($roundingFactorCoefficient
/ Mage_Catalog_Model_Resource_Layer_Filter_Price::MIN_POSSIBLE_PRICE);
$result[$index] = $roundPrices;
$result[(string) $index] = $roundPrices;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,15 @@ public function beforeSave($object)
return;
}

if (!is_array($value['images']) && strlen($value['images']) > 0) {
if (!is_array($value['images']) && (string) $value['images'] !== '') {
$value['images'] = Mage::helper('core')->jsonDecode($value['images']);
}

if (!isset($value['values'])) {
$value['values'] = [];
}

if (!is_array($value['values']) && strlen($value['values']) > 0) {
if (!is_array($value['values']) && (string) $value['values'] !== '') {
$value['values'] = Mage::helper('core')->jsonDecode($value['values']);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function validateUserValue($values)
*/
public function prepareForCart()
{
if ($this->getIsValid() && strlen($this->getUserValue()) > 0) {
if ($this->getIsValid() && $this->getUserValue() !== '') {
return $this->getUserValue();
} else {
return null;
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Catalog/Model/Resource/Abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ protected function _canUpdateAttribute(
protected function _prepareValueForSave($value, Mage_Eav_Model_Entity_Attribute_Abstract $attribute)
{
$type = $attribute->getBackendType();
if (($type === 'int' || $type === 'decimal' || $type === 'datetime') && $value === '') {
if ((in_array($type, ['int', 'decimal', 'datetime'], true)) && $value === '') {
$value = null;
}

Expand Down
6 changes: 3 additions & 3 deletions app/code/core/Mage/Catalog/Model/Resource/Category/Flat.php
Original file line number Diff line number Diff line change
Expand Up @@ -1082,9 +1082,9 @@ public function move(array $affectedCategoryIds)
// add/update
foreach ($addStores as $storeId => $storeCategoryIds) {
$attributeValues = $this->_getAttributeValues(array_keys($storeCategoryIds), $storeId);
foreach ($storeCategoryIds as $row) {
$data = new Varien_Object($row);
$data->addData($attributeValues[$row['entity_id']])
foreach ($storeCategoryIds as $storeCategoryId) {
$data = new Varien_Object($storeCategoryId);
$data->addData($attributeValues[$storeCategoryId['entity_id']])
->setStoreId($storeId);
$this->_synchronize($data);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ public static function initLabels($storeId = null)
$attributeLabels = [];
$attributes = Mage::getResourceSingleton('catalog/product')->getAttributesByCode();
foreach ($attributes as $attribute) {
if (strlen($attribute->getData('frontend_label')) > 0) {
if ((string) $attribute->getData('frontend_label') !== '') {
$attributeLabels[] = $attribute->getData('frontend_label');
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1163,7 +1163,7 @@ public function updateChildrenDataFromParent($storeId, $productIds = null)

$select = $adapter->select();
foreach (array_keys($this->getFlatColumns()) as $columnName) {
if ($columnName === 'entity_id' || $columnName === 'child_id' || $columnName === 'is_child') {
if (in_array($columnName, ['entity_id', 'child_id', 'is_child'], true)) {
continue;
}

Expand Down
15 changes: 8 additions & 7 deletions app/code/core/Mage/Catalog/Model/Resource/Product/Option.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,14 @@ protected function _saveValuePrices(Mage_Core_Model_Abstract $object)
* If there is not price skip saving price
*/

if ($object->getType() == Mage_Catalog_Model_Product_Option::OPTION_TYPE_FIELD
|| $object->getType() == Mage_Catalog_Model_Product_Option::OPTION_TYPE_AREA
|| $object->getType() == Mage_Catalog_Model_Product_Option::OPTION_TYPE_FILE
|| $object->getType() == Mage_Catalog_Model_Product_Option::OPTION_TYPE_DATE
|| $object->getType() == Mage_Catalog_Model_Product_Option::OPTION_TYPE_DATE_TIME
|| $object->getType() == Mage_Catalog_Model_Product_Option::OPTION_TYPE_TIME
) {
if (in_array($object->getType(), [
Mage_Catalog_Model_Product_Option::OPTION_TYPE_FIELD,
Mage_Catalog_Model_Product_Option::OPTION_TYPE_AREA,
Mage_Catalog_Model_Product_Option::OPTION_TYPE_FILE,
Mage_Catalog_Model_Product_Option::OPTION_TYPE_DATE,
Mage_Catalog_Model_Product_Option::OPTION_TYPE_DATE_TIME,
Mage_Catalog_Model_Product_Option::OPTION_TYPE_TIME,
])) {
//save for store_id = 0
if (!$object->getData('scope', 'price')) {
$statement = $readAdapter->select()
Expand Down
4 changes: 2 additions & 2 deletions app/code/core/Mage/CatalogIndex/Model/Indexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -643,15 +643,15 @@ public function buildEntityPriceFilter($attributes, $values, &$filteredAttribute
$rateConversion = $this->_getBaseToSpecifiedCurrencyRate($currentStoreCurrency);
}

if (strlen($values[$code]['from']) > 0) {
if ((string) $values[$code]['from'] !== '') {
$filter[$code]->where(
"($table.min_price"
. implode('', $additionalCalculations[$code]) . ")*{$rateConversion} >= ?",
$values[$code]['from'],
);
}

if (strlen($values[$code]['to']) > 0) {
if ((string) $values[$code]['to'] !== '') {
$filter[$code]->where(
"($table.min_price"
. implode('', $additionalCalculations[$code]) . ")*{$rateConversion} <= ?",
Expand Down
6 changes: 3 additions & 3 deletions app/code/core/Mage/CatalogSearch/Model/Advanced.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,16 +237,16 @@ protected function _addSearchCriteria($attribute, $value)
$currencyModel = null;
}

if (strlen($value['from']) > 0 && strlen($value['to']) > 0) {
if ((string) $value['from'] !== '' && (string) $value['to'] !== '') {
$value = sprintf(
'%s - %s',
($currencyModel ? $from : $value['from']),
($currencyModel ? $to : $value['to']),
);
} elseif (strlen($value['from']) > 0) {
} elseif ((string) $value['from'] !== '') {
// and more
$value = Mage::helper('catalogsearch')->__('%s and greater', ($currencyModel ? $from : $value['from']));
} elseif (strlen($value['to']) > 0) {
} elseif ((string) $value['to'] !== '') {
// to
$value = Mage::helper('catalogsearch')->__('up to %s', ($currencyModel ? $to : $value['to']));
}
Expand Down
6 changes: 3 additions & 3 deletions app/code/core/Mage/CatalogSearch/Model/Resource/Advanced.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function prepareCondition($attribute, $value, $collection)
} elseif (!isset($value['from']) && !isset($value['to'])) { // select
$condition = ['in' => $value];
}
} elseif (strlen($value) > 0) {
} elseif ((string) $value !== '') {
if (in_array($attribute->getBackendType(), ['varchar', 'text', 'static'])) {
$condition = ['like' => '%' . $value . '%']; // text search
} else {
Expand All @@ -90,15 +90,15 @@ public function addRatedPriceFilter($collection, $attribute, $value, $rate = 1)
$adapter = $this->_getReadAdapter();

$conditions = [];
if (strlen($value['from']) > 0) {
if ((string) $value['from'] !== '') {
$conditions[] = $adapter->quoteInto(
'price_index.min_price %s * %s >= ?',
$value['from'],
Zend_Db::FLOAT_TYPE,
);
}

if (strlen($value['to']) > 0) {
if ((string) $value['to'] !== '') {
$conditions[] = $adapter->quoteInto(
'price_index.min_price %s * %s <= ?',
$value['to'],
Expand Down
4 changes: 2 additions & 2 deletions app/code/core/Mage/Core/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,8 @@ public function validateHash($password, $hash)
public function getVersionHash(Mage_Core_Model_Encryption $encryptionModel)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the parameter isn't used anymore, maybe deprecate it?

Copy link
Contributor Author

@sreichel sreichel Oct 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its not an optional parameter.

{
return function_exists('password_hash')
? $encryptionModel::HASH_VERSION_LATEST
: $encryptionModel::HASH_VERSION_SHA512;
? Mage_Core_Model_Encryption::HASH_VERSION_LATEST
: Mage_Core_Model_Encryption::HASH_VERSION_SHA512;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Core/Model/Resource/Abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ protected function _prepareDataForTable(Varien_Object $object, $table)
*/
protected function _prepareTableValueForSave($value, $type)
{
if ($type == 'decimal' || $type == 'numeric' || $type == 'float') {
if (in_array($type, ['decimal', 'numeric', 'float'])) {
return Mage::app()->getLocale()->getNumber($value);
}

Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Customer/Model/Address/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function getFormats()
$path = sprintf('%s%s', self::XML_PATH_ADDRESS_TEMPLATE, $typeCode);
$type = new Varien_Object();
$htmlEscape = strtolower((string) $typeConfig->htmlEscape);
$htmlEscape = !($htmlEscape == 'false' || $htmlEscape == '0' || $htmlEscape == 'no'
$htmlEscape = !(in_array($htmlEscape, ['false', '0', 'no'])
|| !strlen($htmlEscape));
$type->setCode($typeCode)
->setTitle((string) $typeConfig->title)
Expand Down
4 changes: 2 additions & 2 deletions app/code/core/Mage/Downloadable/Model/Link/Api/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public function validateFileDetails(&$var)
protected function _dispatch(&$resource, $fields)
{
foreach ($fields as $name => $validator) {
if (is_string($validator) && strlen($validator) > 0 && array_key_exists($name, $resource)) {
if (is_string($validator) && $validator !== '' && array_key_exists($name, $resource)) {
$call = 'validate' . $validator;
$this->$call($resource[$name]);
}
Expand Down Expand Up @@ -243,7 +243,7 @@ public function validateFile(&$var)
*/
public function validateUrl(&$var)
{
if (is_string($var) && strlen($var) > 0) {
if (is_string($var) && $var !== '') {
$urlregex = "/^(https?|ftp)\:\/\/([a-z0-9+\!\*\(\)\,\;\?\&\=\$\_\.\-]+(\:[a-z0-9+\!\*\(\)\,\;\?\&\=\$\_\.\-]+)?@)?[a-z0-9\+\$\_\-]+(\.[a-z0-9+\$\_\-]+)*(\:[0-9]{2,5})?(\/([a-z0-9+\$\_\-]\.?)+)*\/?(\?[a-z\+\&\$\_\.\-][a-z0-9\;\:\@\/\&\%\=\+\$\_\.\-]*)?(#[a-z\_\.\-][a-z0-9\+\$\_\.\-]*)?$/i";
if (!preg_match($urlregex, $var)) {
throw new Exception('url_not_valid');
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Eav/Model/Entity/Attribute/Abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ public function isValueEmpty($value)
return is_array($value)
|| ($value === null)
|| $value === false && $attrType !== 'int'
|| $value === '' && ($attrType === 'int' || $attrType === 'decimal' || $attrType === 'datetime');
|| $value === '' && (in_array($attrType, ['int', 'decimal', 'datetime'], true));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@ protected function _prepareExport()
$row[$column] = array_shift($multiSelectOptions);
}

unset($multiSelectOptions);

$writeRow = array_merge($row, $addrRow);
$writer->writeRow($writeRow);

Expand All @@ -240,6 +242,8 @@ protected function _prepareExport()
$writeRow[$column] = array_shift($multiSelectOptions);
}

unset($multiSelectOptions);

if (!$this->_isExistMultiSelectOptions($addressMultiselect, $currentAddressId)) {
[$addressId, $addrRow] = $this->_getNextAddressRow($customerAddress);
$currentAddressId = $addressId;
Expand Down
14 changes: 8 additions & 6 deletions app/code/core/Mage/ImportExport/Model/Export/Entity/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -901,6 +901,8 @@ protected function _prepareExport()
$options = null;
}

unset($storeId);

foreach ($customOptionsDataPre as $productId => &$optionsData) {
$customOptionsData[$productId] = [];

Expand Down Expand Up @@ -991,6 +993,8 @@ protected function _prepareExport()
}
}

unset($colPrefix);

if (!empty($customOptionsData[$productId])) {
$dataRow = array_merge($dataRow, array_shift($customOptionsData[$productId]));
}
Expand All @@ -1001,9 +1005,7 @@ protected function _prepareExport()

if (!empty($rowMultiselects[$productId][$storeId])) {
foreach (array_keys($rowMultiselects[$productId][$storeId]) as $attrKey) {
if (isset($rowMultiselects[$productId][$storeId][$attrKey])) {
$dataRow[$attrKey] = array_shift($rowMultiselects[$productId][$storeId][$attrKey]);
}
$dataRow[$attrKey] = array_shift($rowMultiselects[$productId][$storeId][$attrKey]);
}
}

Expand Down Expand Up @@ -1083,6 +1085,8 @@ protected function _prepareExport()
}
}

unset($colPrefix);

if (!empty($customOptionsData[$productId])) {
$dataRow = array_merge($dataRow, array_shift($customOptionsData[$productId]));
}
Expand All @@ -1093,9 +1097,7 @@ protected function _prepareExport()

if (!empty($rowMultiselects[$productId][$storeId])) {
foreach (array_keys($rowMultiselects[$productId][$storeId]) as $attrKey) {
if (isset($rowMultiselects[$productId][$storeId][$attrKey])) {
$dataRow[$attrKey] = array_shift($rowMultiselects[$productId][$storeId][$attrKey]);
}
$dataRow[$attrKey] = array_shift($rowMultiselects[$productId][$storeId][$attrKey]);
}
}

Expand Down
Loading
Loading