Skip to content

Use one format in all places for array_merge #30002

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

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion app/code/Magento/Catalog/Block/Product/ListProduct.php
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ public function getIdentities()
$identities[] = $item->getIdentities();
}
}
$identities = array_merge(...$identities);
$identities = array_merge([], ...$identities);

return $identities;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,11 @@ public function getItems()
*/
public function getIdentities()
{
$identities = [[]];
$identities = [];
foreach ($this->getItems() as $item) {
$identities[] = $item->getIdentities();
}
return array_merge(...$identities);
return array_merge([], ...$identities);
}

/**
Expand Down
10 changes: 5 additions & 5 deletions app/code/Magento/Catalog/Block/Product/ProductList/Upsell.php
Original file line number Diff line number Diff line change
Expand Up @@ -267,10 +267,10 @@ public function getItemLimit($type = '')
*/
public function getIdentities()
{
$identities = array_map(function (DataObject $item) {
return $item->getIdentities();
}, $this->getItems()) ?: [[]];

return array_merge(...$identities);
$identities = [];
foreach ($this->getItems() as $item) {
$identities[] = $item->getIdentities();
}
return array_merge([], ...$identities);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -270,14 +270,14 @@ private function getCategoryIdsFromIndex(array $productIds): array
);
$categoryIds[] = $storeCategories;
}
$categoryIds = array_merge(...$categoryIds);
$categoryIds = array_merge([], ...$categoryIds);

$parentCategories = [$categoryIds];
foreach ($categoryIds as $categoryId) {
$parentIds = explode('/', $this->getPathFromCategoryId($categoryId));
$parentCategories[] = $parentIds;
}
$categoryIds = array_unique(array_merge(...$parentCategories));
$categoryIds = array_unique(array_merge([], ...$parentCategories));

return $categoryIds;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ protected function _fillTemporaryFlatTable(array $tables, $storeId, $valueFieldS

$select->from(
['et' => $entityTemporaryTableName],
array_merge(...$allColumns)
array_merge([], ...$allColumns)
)->joinInner(
['e' => $this->resource->getTableName('catalog_product_entity')],
'e.entity_id = et.entity_id',
Expand Down Expand Up @@ -306,7 +306,7 @@ protected function _fillTemporaryFlatTable(array $tables, $storeId, $valueFieldS
$allColumns[] = $columnValueNames;
}
}
$sql = $select->insertFromSelect($temporaryFlatTableName, array_merge(...$allColumns), false);
$sql = $select->insertFromSelect($temporaryFlatTableName, array_merge([], ...$allColumns), false);
$this->_connection->query($sql);
}

Expand Down
9 changes: 3 additions & 6 deletions app/code/Magento/Catalog/Model/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -835,10 +835,7 @@ public function getStoreIds()
$storeIds[] = $websiteStores;
}
}
if ($storeIds) {
$storeIds = array_merge(...$storeIds);
}
$this->setStoreIds($storeIds);
$this->setStoreIds(array_merge([], ...$storeIds));
}
return $this->getData('store_ids');
}
Expand Down Expand Up @@ -1033,7 +1030,7 @@ public function priceReindexCallback()
*/
public function eavReindexCallback()
{
if ($this->isObjectNew() || $this->isDataChanged($this)) {
if ($this->isObjectNew() || $this->isDataChanged()) {
$this->_productEavIndexerProcessor->reindexRow($this->getEntityId());
}
}
Expand Down Expand Up @@ -1179,7 +1176,7 @@ public function getTierPrice($qty = null)
/**
* Get formatted by currency product price
*
* @return array|double
* @return array|double
* @since 102.0.6
*/
public function getFormattedPrice()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
use Magento\Catalog\Model\Product\Price\Validation\TierPriceValidator;
use Magento\Catalog\Model\ProductIdLocatorInterface;

/**
* Tier price storage.
*/
class TierPriceStorage implements TierPriceStorageInterface
{
/**
Expand Down Expand Up @@ -220,7 +217,7 @@ private function retrieveAffectedIds(array $skus): array
$affectedIds[] = array_keys($productId);
}

return $affectedIds ? array_unique(array_merge(...$affectedIds)) : [];
return array_unique(array_merge([], ...$affectedIds));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ private function extractRequestedLinkTypes(array $criteria): array
if (count($linkTypesToLoad) === 1) {
$linkTypesToLoad = $linkTypesToLoad[0];
} else {
$linkTypesToLoad = array_merge(...$linkTypesToLoad);
$linkTypesToLoad = array_merge([], ...$linkTypesToLoad);
}
$linkTypesToLoad = array_flip($linkTypesToLoad);
$linkTypes = array_filter(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function build(int $productId, int $storeId) : array
foreach ($this->linkedProductSelectBuilder as $productSelectBuilder) {
$selects[] = $productSelectBuilder->build($productId, $storeId);
}
$selects = array_merge(...$selects);
$selects = array_merge([], ...$selects);

return $selects;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ function (AggregationValueInterface $value) {
return [];
}

return $this->attributeOptionProvider->getOptions(\array_merge(...$attributeOptionIds), $storeId, $attributes);
return $this->attributeOptionProvider->getOptions(
\array_merge([], ...$attributeOptionIds),
$storeId,
$attributes
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function build(AggregationInterface $aggregation, ?int $storeId): array
foreach ($this->builders as $builder) {
$layers[] = $builder->build($aggregation, $storeId);
}
$layers = \array_merge(...$layers);
$layers = \array_merge([], ...$layers);

return \array_filter($layers);
}
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/CatalogGraphQl/Model/AttributesJoiner.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function getQueryFields(FieldNode $fieldNode, ResolveInfo $resolveInfo):
}
}
if ($fragmentFields) {
$selectedFields = array_merge($selectedFields, array_merge(...$fragmentFields));
$selectedFields = array_merge([], $selectedFields, ...$fragmentFields);
}
$this->setSelectionsForFieldNode($fieldNode, array_unique($selectedFields));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function apply(Filter $filter, AbstractDb $collection)
$collection->addCategoryFilter($category);
}

$categoryProductIds = array_unique(array_merge(...$categoryProducts));
$categoryProductIds = array_unique(array_merge([], ...$categoryProducts));
$collection->addIdFilter($categoryProductIds);
return true;
}
Expand Down
8 changes: 4 additions & 4 deletions app/code/Magento/CatalogInventory/Model/StockIndex.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,11 @@ protected function processChildren(

$requiredChildrenIds = $typeInstance->getChildrenIds($productId, true);
if ($requiredChildrenIds) {
$childrenIds = [[]];
$childrenIds = [];
foreach ($requiredChildrenIds as $groupedChildrenIds) {
$childrenIds[] = $groupedChildrenIds;
}
$childrenIds = array_merge(...$childrenIds);
$childrenIds = array_merge([], ...$childrenIds);

$childrenWebsites = $this->productWebsite->getWebsites($childrenIds);
foreach ($websitesWithStores as $websiteId => $storeId) {
Expand Down Expand Up @@ -232,13 +232,13 @@ protected function getWebsitesWithDefaultStores($websiteId = null)
*/
protected function processParents($productId, $websiteId)
{
$parentIds = [[]];
$parentIds = [];
foreach ($this->getProductTypeInstances() as $typeInstance) {
/* @var ProductType\AbstractType $typeInstance */
$parentIds[] = $typeInstance->getParentIdsByChild($productId);
}

$parentIds = array_merge(...$parentIds);
$parentIds = array_merge([], ...$parentIds);

if (empty($parentIds)) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function apply(\Magento\Framework\App\RequestInterface $request)
$label = $this->getOptionText($value);
$labels[] = is_array($label) ? $label : [$label];
}
$label = implode(',', array_unique(array_merge(...$labels)));
$label = implode(',', array_unique(array_merge([], ...$labels)));
$this->getLayer()
->getState()
->addFilter($this->_createItem($label, $attributeValue));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public function afterSave(
*/
protected function generateProductUrls($websiteId, $originWebsiteId)
{
$urls = [[]];
$urls = [];
$websiteIds = $websiteId != $originWebsiteId
? [$websiteId, $originWebsiteId]
: [$websiteId];
Expand All @@ -136,7 +136,7 @@ protected function generateProductUrls($websiteId, $originWebsiteId)
$urls[] = $this->productUrlRewriteGenerator->generate($product);
}

return array_merge(...$urls);
return array_merge([], ...$urls);
}

/**
Expand All @@ -148,7 +148,7 @@ protected function generateProductUrls($websiteId, $originWebsiteId)
*/
protected function generateCategoryUrls($rootCategoryId, $storeIds)
{
$urls = [[]];
$urls = [];
$categories = $this->categoryFactory->create()->getCategories($rootCategoryId, 1, false, true);
foreach ($categories as $category) {
/** @var \Magento\Catalog\Model\Category $category */
Expand All @@ -157,6 +157,6 @@ protected function generateCategoryUrls($rootCategoryId, $storeIds)
$urls[] = $this->categoryUrlRewriteGenerator->generate($category);
}

return array_merge(...$urls);
return array_merge([], ...$urls);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@
use RuntimeException;

/**
* Class AfterImportDataObserver
*
* @SuppressWarnings(PHPMD.TooManyFields)
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
Expand Down Expand Up @@ -459,8 +457,7 @@ private function categoriesUrlRewriteGenerate(): array
}
}
}
$result = !empty($urls) ? array_merge(...$urls) : [];
return $result;
return array_merge([], ...$urls);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions app/code/Magento/CatalogWidget/Block/Product/ProductsList.php
Original file line number Diff line number Diff line change
Expand Up @@ -506,15 +506,15 @@ public function getPagerHtml()
*/
public function getIdentities()
{
$identities = [[]];
$identities = [];
if ($this->getProductCollection()) {
foreach ($this->getProductCollection() as $product) {
if ($product instanceof IdentityInterface) {
$identities[] = $product->getIdentities();
}
}
}
$identities = array_merge(...$identities);
$identities = array_merge([], ...$identities);

return $identities ?: [Product::CACHE_TAG];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ public function __construct($list = null)
public function isValid($agreementIds = [])
{
$agreementIds = $agreementIds === null ? [] : $agreementIds;
$requiredAgreements = [[]];
$requiredAgreements = [];
foreach ($this->agreementsProviders as $agreementsProvider) {
$requiredAgreements[] = $agreementsProvider->getRequiredAgreementIds();
}

$agreementsDiff = array_diff(array_merge(...$requiredAgreements), $agreementIds);
$agreementsDiff = array_diff(array_merge([], ...$requiredAgreements), $agreementIds);

return empty($agreementsDiff);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ $filters = $block->getConfig()->getFilters() ?? [];
$allowedExtensions = [];
$blockHtmlId = $block->getHtmlId();

$listExtensions = [[]];
$listExtensions = [];
foreach ($filters as $media_type) {
$listExtensions[] = array_map(function ($fileExt) {
return ltrim($fileExt, '.*');
}, $media_type['files']);
}

$allowedExtensions = array_merge(...$listExtensions);
$allowedExtensions = array_merge([], ...$listExtensions);

$resizeConfig = $block->getImageUploadConfigData()->getIsResizeEnabled()
? "{action: 'resize', maxWidth: "
Expand Down
4 changes: 2 additions & 2 deletions app/code/Magento/Csp/Helper/InlineUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,14 @@ private function extractHost(string $url): ?string
*/
private function extractRemoteFonts(string $styleContent): array
{
$urlsFound = [[]];
$urlsFound = [];
preg_match_all('/\@font\-face\s*?\{([^\}]*)[^\}]*?\}/im', $styleContent, $fontFaces);
foreach ($fontFaces[1] as $fontFaceContent) {
preg_match_all('/url\([\'\"]?(http(s)?\:[^\)]+)[\'\"]?\)/i', $fontFaceContent, $urls);
$urlsFound[] = $urls[1];
}

return array_map([$this, 'extractHost'], array_merge(...$urlsFound));
return array_map([$this, 'extractHost'], array_merge([], ...$urlsFound));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ protected function _unserializeStoreConfig($configPath, $storeId = null)
*/
protected function getAllowedCurrencies()
{
$allowedCurrencies = [[]];
$allowedCurrencies = [];
$allowedCurrencies[] = explode(
self::ALLOWED_CURRENCIES_CONFIG_SEPARATOR,
$this->_scopeConfig->getValue(
Expand Down Expand Up @@ -330,6 +330,6 @@ protected function getAllowedCurrencies()
}
}
}
return array_unique(array_merge(...$allowedCurrencies));
return array_unique(array_merge([], ...$allowedCurrencies));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ public function __construct(
*/
public function validate(AbstractAddress $address)
{
$errors = [[]];
$errors = [];
foreach ($this->validators as $validator) {
$errors[] = $validator->validate($address);
}

return array_merge(...$errors);
return array_merge([], ...$errors);
}
}
4 changes: 2 additions & 2 deletions app/code/Magento/Customer/Model/Metadata/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -363,11 +363,11 @@ public function validateData(array $data)
{
$validator = $this->_getValidator($data);
if (!$validator->isValid(false)) {
$messages = [[]];
$messages = [];
foreach ($validator->getMessages() as $errorMessages) {
$messages[] = (array)$errorMessages;
}
return array_merge(...$messages);
return array_merge([], ...$messages);
}
return true;
}
Expand Down
Loading