Skip to content

Commit

Permalink
rector Php74: ClosureToArrowFunctionRector
Browse files Browse the repository at this point in the history
  • Loading branch information
sreichel committed Mar 9, 2025
1 parent 5a199a3 commit 03e82e7
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 42 deletions.
4 changes: 1 addition & 3 deletions app/code/core/Mage/Adminhtml/Block/Widget/Grid.php
Original file line number Diff line number Diff line change
Expand Up @@ -559,9 +559,7 @@ protected function _addColumnFilterToCollection($column)
} else {
$cond = $column->getFilter()->getCondition();
if ($field && $cond !== null) {
$filtered = array_map(static function ($value) {
return is_object($value) ? $value->__toString() : $value;
}, is_array($cond) ? array_values($cond) : [$cond]);
$filtered = array_map(static fn($value) => is_object($value) ? $value->__toString() : $value, is_array($cond) ? array_values($cond) : [$cond]);
if (in_array('\'%NULL%\'', $filtered, true) || in_array('NULL', $filtered, true)) {
$this->getCollection()->addFieldToFilter($field, ['null' => true]);
} else {
Expand Down
4 changes: 1 addition & 3 deletions app/code/core/Mage/Api/Model/Server/Handler/Abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -608,9 +608,7 @@ public function processingRow($row)
{
return preg_replace_callback(
'/[^\x{0009}\x{000a}\x{000d}\x{0020}-\x{D7FF}\x{E000}-\x{FFFD}\x{10000}-\x{10FFFF}]/u',
function ($matches) {
return '&#' . Mage::helper('core/string')->uniOrd($matches[0]) . ';';
},
fn($matches) => '&#' . Mage::helper('core/string')->uniOrd($matches[0]) . ';',
$row,
);
}
Expand Down
4 changes: 1 addition & 3 deletions app/code/core/Mage/Catalog/Model/Layer.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,7 @@ public function getFilterableAttributes()
}
}
}
uasort($attributes, function ($a, $b) {
return $a->getPosition() - $b->getPosition();
});
uasort($attributes, fn($a, $b) => $a->getPosition() - $b->getPosition());

return $attributes;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,7 @@ protected function _loadPrices()
}
}

uasort($values, function ($a, $b) {
return $a['order'] - $b['order'];
});
uasort($values, fn($a, $b) => $a['order'] - $b['order']);

foreach ($pricings[0] as $pricing) {
// Adding pricing to options
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,7 @@ public function attachProductChildrenAttributeMapping(array $parentProducts, $st
}

// normalize to all lower case before we start using them
$optionLabels = array_map(function ($value) {
return array_map('Mage_ConfigurableSwatches_Helper_Data::normalizeKey', $value);
}, $optionLabels);
$optionLabels = array_map(fn($value) => array_map('Mage_ConfigurableSwatches_Helper_Data::normalizeKey', $value), $optionLabels);

foreach ($parentProducts as $parentProduct) {
$mapping = [];
Expand Down Expand Up @@ -178,9 +176,7 @@ public function getConfigurableImagesFallbackArray(
$imageTypes = array_intersect(['image', 'small_image'], $imageTypes);

$imagesByLabel = [];
$imageHaystack = array_map(function ($value) {
return Mage_ConfigurableSwatches_Helper_Data::normalizeKey($value['label']);
}, $mediaGallery['images']);
$imageHaystack = array_map(fn($value) => Mage_ConfigurableSwatches_Helper_Data::normalizeKey($value['label']), $mediaGallery['images']);

// load images from the configurable product for swapping
if (is_array($mapping)) {
Expand Down
8 changes: 2 additions & 6 deletions app/code/core/Mage/ConfigurableSwatches/Helper/Productimg.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,7 @@ public function indexProductImages($product, $preValues = null)
return; //nothing to do here
}

$imageHaystack = array_map(function ($value) {
return Mage_ConfigurableSwatches_Helper_Data::normalizeKey($value['label']);
}, $mediaGallery['images']);
$imageHaystack = array_map(fn($value) => Mage_ConfigurableSwatches_Helper_Data::normalizeKey($value['label']), $mediaGallery['images']);

foreach ($searchValues as $label) {
$imageKeys = [];
Expand Down Expand Up @@ -385,9 +383,7 @@ public function filterImageInGallery($product, $image)
if (!isset($this->_productImageFilters[$product->getId()])) {
$mapping = call_user_func_array('array_merge_recursive', array_values($product->getChildAttributeLabelMapping()));
$filters = array_unique($mapping['labels']);
$filters = array_merge($filters, array_map(function ($label) {
return $label . Mage_ConfigurableSwatches_Helper_Productimg::SWATCH_LABEL_SUFFIX;
}, $filters));
$filters = array_merge($filters, array_map(fn($label) => $label . Mage_ConfigurableSwatches_Helper_Productimg::SWATCH_LABEL_SUFFIX, $filters));
$this->_productImageFilters[$product->getId()] = $filters;
}

Expand Down
4 changes: 1 addition & 3 deletions app/code/core/Mage/Core/Helper/Abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,7 @@ public function removeTags($html)
{
$html = preg_replace_callback(
"# <(?![/a-z]) | (?<=\s)>(?![a-z]) #xi",
function ($matches) {
return htmlentities($matches[0]);
},
fn($matches) => htmlentities($matches[0]),
$html,
);
$html = strip_tags($html);
Expand Down
20 changes: 5 additions & 15 deletions lib/Varien/Data/Collection/Db.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,7 @@ public function getSelectCountSql()
$countSelect->reset(Zend_Db_Select::GROUP);
$countSelect->distinct(true);
$group = $this->getSelect()->getPart(Zend_Db_Select::GROUP);
$group = array_map(function ($token) {
return $this->getSelect()->getAdapter()->quoteIdentifier($token, true);
}, $group);
$group = array_map(fn($token) => $this->getSelect()->getAdapter()->quoteIdentifier($token, true), $group);
$countSelect->columns('COUNT(DISTINCT ' . implode(', ', $group) . ')');
} else {
$countSelect->columns('COUNT(*)');
Expand All @@ -244,13 +242,9 @@ public function getSelectCountSql()
// - there are no where clauses using joined tables
// - all joins are left joins
// - there are no join conditions using bind params (for simplicity)
$leftJoins = array_filter($countSelect->getPart(Zend_Db_Select::FROM), function ($table) {
return ($table['joinType'] == Zend_Db_Select::LEFT_JOIN || $table['joinType'] == Zend_Db_Select::FROM);
});
$leftJoins = array_filter($countSelect->getPart(Zend_Db_Select::FROM), fn($table) => $table['joinType'] == Zend_Db_Select::LEFT_JOIN || $table['joinType'] == Zend_Db_Select::FROM);
if (count($leftJoins) == count($countSelect->getPart(Zend_Db_Select::FROM))) {
$mainTable = array_filter($leftJoins, function ($table) {
return $table['joinType'] == Zend_Db_Select::FROM;
});
$mainTable = array_filter($leftJoins, fn($table) => $table['joinType'] == Zend_Db_Select::FROM);
$mainTable = key($mainTable);
$mainTable = preg_quote($mainTable, '/');
$pattern = "/^$mainTable\\.\\w+/";
Expand All @@ -262,13 +256,9 @@ public function getSelectCountSql()
});
});
if ($this->_bindParams) {
$bindParams = array_map(function ($token) {
return ltrim($token, ':');
}, array_keys($this->_bindParams));
$bindParams = array_map(fn($token) => ltrim($token, ':'), array_keys($this->_bindParams));
$bindPattern = '/:(' . implode('|', $bindParams) . ')/';
$joinUsingBind = array_filter($leftJoins, function ($table) use ($bindPattern) {
return !empty($table['joinCondition']) && preg_match($bindPattern, $table['joinCondition']);
});
$joinUsingBind = array_filter($leftJoins, fn($table) => !empty($table['joinCondition']) && preg_match($bindPattern, $table['joinCondition']));
}
if (empty($whereUsingJoin) && empty($joinUsingBind)) {
$from = array_slice($leftJoins, 0, 1);
Expand Down

0 comments on commit 03e82e7

Please sign in to comment.