diff --git a/app/code/Magento/Catalog/Block/Product/ProductList/Related.php b/app/code/Magento/Catalog/Block/Product/ProductList/Related.php index 24811d61a7715..387fac770c5bc 100644 --- a/app/code/Magento/Catalog/Block/Product/ProductList/Related.php +++ b/app/code/Magento/Catalog/Block/Product/ProductList/Related.php @@ -6,7 +6,15 @@ namespace Magento\Catalog\Block\Product\ProductList; +use Magento\Catalog\Block\Product\AbstractProduct; +use Magento\Catalog\Block\Product\Context; +use Magento\Catalog\Model\Product; +use Magento\Catalog\Model\Product\Visibility as ProductVisibility; use Magento\Catalog\Model\ResourceModel\Product\Collection; +use Magento\Checkout\Model\ResourceModel\Cart as CartResourceModel; +use Magento\Checkout\Model\Session as CheckoutSession; +use Magento\Framework\DataObject\IdentityInterface; +use Magento\Framework\Module\Manager; use Magento\Framework\View\Element\AbstractBlock; /** @@ -16,8 +24,7 @@ * @SuppressWarnings(PHPMD.LongVariable) * @since 100.0.2 */ -class Related extends \Magento\Catalog\Block\Product\AbstractProduct implements - \Magento\Framework\DataObject\IdentityInterface +class Related extends AbstractProduct implements IdentityInterface { /** * @var Collection @@ -27,53 +34,50 @@ class Related extends \Magento\Catalog\Block\Product\AbstractProduct implements /** * Checkout session * - * @var \Magento\Checkout\Model\Session + * @var CheckoutSession */ protected $_checkoutSession; /** * Catalog product visibility * - * @var \Magento\Catalog\Model\Product\Visibility + * @var ProductVisibility */ protected $_catalogProductVisibility; /** * Checkout cart * - * @var \Magento\Checkout\Model\ResourceModel\Cart + * @var CartResourceModel */ protected $_checkoutCart; /** - * @var \Magento\Framework\Module\Manager + * @var Manager */ protected $moduleManager; /** - * @param \Magento\Catalog\Block\Product\Context $context - * @param \Magento\Checkout\Model\ResourceModel\Cart $checkoutCart - * @param \Magento\Catalog\Model\Product\Visibility $catalogProductVisibility - * @param \Magento\Checkout\Model\Session $checkoutSession - * @param \Magento\Framework\Module\Manager $moduleManager + * @param Context $context + * @param CartResourceModel $checkoutCart + * @param ProductVisibility $catalogProductVisibility + * @param CheckoutSession $checkoutSession + * @param Manager $moduleManager * @param array $data */ public function __construct( - \Magento\Catalog\Block\Product\Context $context, - \Magento\Checkout\Model\ResourceModel\Cart $checkoutCart, - \Magento\Catalog\Model\Product\Visibility $catalogProductVisibility, - \Magento\Checkout\Model\Session $checkoutSession, - \Magento\Framework\Module\Manager $moduleManager, + Context $context, + CartResourceModel $checkoutCart, + ProductVisibility $catalogProductVisibility, + CheckoutSession $checkoutSession, + Manager $moduleManager, array $data = [] ) { $this->_checkoutCart = $checkoutCart; $this->_catalogProductVisibility = $catalogProductVisibility; $this->_checkoutSession = $checkoutSession; $this->moduleManager = $moduleManager; - parent::__construct( - $context, - $data - ); + parent::__construct($context, $data); } /** @@ -84,7 +88,7 @@ public function __construct( protected function _prepareData() { $product = $this->getProduct(); - /* @var $product \Magento\Catalog\Model\Product */ + /* @var $product Product */ $this->_itemCollection = $product->getRelatedProductCollection()->addAttributeToSelect( 'required_options' @@ -139,12 +143,11 @@ public function getItems() */ public function getIdentities() { - $identities = []; + $identities = [[]]; foreach ($this->getItems() as $item) { - // phpcs:ignore Magento2.Performance.ForeachArrayMerge - $identities = array_merge($identities, $item->getIdentities()); + $identities[] = $item->getIdentities(); } - return $identities; + return array_merge(...$identities); } /** diff --git a/app/code/Magento/Catalog/Block/Product/ProductList/Upsell.php b/app/code/Magento/Catalog/Block/Product/ProductList/Upsell.php index fa1beaf6e0ea8..ac66392efe5dc 100644 --- a/app/code/Magento/Catalog/Block/Product/ProductList/Upsell.php +++ b/app/code/Magento/Catalog/Block/Product/ProductList/Upsell.php @@ -6,7 +6,16 @@ namespace Magento\Catalog\Block\Product\ProductList; +use Magento\Catalog\Block\Product\AbstractProduct; +use Magento\Catalog\Block\Product\Context; +use Magento\Catalog\Model\Product; +use Magento\Catalog\Model\Product\Visibility as ProductVisibility; use Magento\Catalog\Model\ResourceModel\Product\Collection; +use Magento\Checkout\Model\ResourceModel\Cart as CartResourceModel; +use Magento\Checkout\Model\Session as CheckoutSession; +use Magento\Framework\DataObject; +use Magento\Framework\DataObject\IdentityInterface; +use Magento\Framework\Module\Manager; /** * Catalog product upsell items block @@ -15,8 +24,7 @@ * @SuppressWarnings(PHPMD.LongVariable) * @since 100.0.2 */ -class Upsell extends \Magento\Catalog\Block\Product\AbstractProduct implements - \Magento\Framework\DataObject\IdentityInterface +class Upsell extends AbstractProduct implements IdentityInterface { /** * @var int @@ -24,7 +32,7 @@ class Upsell extends \Magento\Catalog\Block\Product\AbstractProduct implements protected $_columnCount = 4; /** - * @var \Magento\Framework\DataObject[] + * @var DataObject[] */ protected $_items; @@ -41,53 +49,50 @@ class Upsell extends \Magento\Catalog\Block\Product\AbstractProduct implements /** * Checkout session * - * @var \Magento\Checkout\Model\Session + * @var CheckoutSession */ protected $_checkoutSession; /** * Catalog product visibility * - * @var \Magento\Catalog\Model\Product\Visibility + * @var ProductVisibility */ protected $_catalogProductVisibility; /** * Checkout cart * - * @var \Magento\Checkout\Model\ResourceModel\Cart + * @var CartResourceModel */ protected $_checkoutCart; /** - * @var \Magento\Framework\Module\Manager + * @var Manager */ protected $moduleManager; /** - * @param \Magento\Catalog\Block\Product\Context $context - * @param \Magento\Checkout\Model\ResourceModel\Cart $checkoutCart - * @param \Magento\Catalog\Model\Product\Visibility $catalogProductVisibility - * @param \Magento\Checkout\Model\Session $checkoutSession - * @param \Magento\Framework\Module\Manager $moduleManager + * @param Context $context + * @param CartResourceModel $checkoutCart + * @param ProductVisibility $catalogProductVisibility + * @param CheckoutSession $checkoutSession + * @param Manager $moduleManager * @param array $data */ public function __construct( - \Magento\Catalog\Block\Product\Context $context, - \Magento\Checkout\Model\ResourceModel\Cart $checkoutCart, - \Magento\Catalog\Model\Product\Visibility $catalogProductVisibility, - \Magento\Checkout\Model\Session $checkoutSession, - \Magento\Framework\Module\Manager $moduleManager, + Context $context, + CartResourceModel $checkoutCart, + ProductVisibility $catalogProductVisibility, + CheckoutSession $checkoutSession, + Manager $moduleManager, array $data = [] ) { $this->_checkoutCart = $checkoutCart; $this->_catalogProductVisibility = $catalogProductVisibility; $this->_checkoutSession = $checkoutSession; $this->moduleManager = $moduleManager; - parent::__construct( - $context, - $data - ); + parent::__construct($context, $data); } /** @@ -98,7 +103,7 @@ public function __construct( protected function _prepareData() { $product = $this->getProduct(); - /* @var $product \Magento\Catalog\Model\Product */ + /* @var $product Product */ $this->_itemCollection = $product->getUpSellProductCollection()->setPositionOrder()->addStoreFilter(); if ($this->moduleManager->isEnabled('Magento_Checkout')) { $this->_addProductAttributesAndPrices($this->_itemCollection); @@ -181,8 +186,8 @@ public function getRowCount() */ public function setColumnCount($columns) { - if ((int) $columns > 0) { - $this->_columnCount = (int) $columns; + if ((int)$columns > 0) { + $this->_columnCount = (int)$columns; } return $this; } @@ -231,8 +236,8 @@ public function getIterableItem() */ public function setItemLimit($type, $limit) { - if ((int) $limit > 0) { - $this->_itemLimits[$type] = (int) $limit; + if ((int)$limit > 0) { + $this->_itemLimits[$type] = (int)$limit; } return $this; } @@ -250,9 +255,9 @@ public function getItemLimit($type = '') } if (isset($this->_itemLimits[$type])) { return $this->_itemLimits[$type]; - } else { - return 0; } + + return 0; } /** @@ -262,11 +267,10 @@ public function getItemLimit($type = '') */ public function getIdentities() { - $identities = []; - foreach ($this->getItems() as $item) { - // phpcs:ignore Magento2.Performance.ForeachArrayMerge - $identities = array_merge($identities, $item->getIdentities()); - } - return $identities; + $identities = array_map(function (DataObject $item) { + return $item->getIdentities(); + }, $this->getItems()) ?: [[]]; + + return array_merge(...$identities); } } diff --git a/app/code/Magento/Catalog/Test/Unit/Block/Product/ProductList/UpsellTest.php b/app/code/Magento/Catalog/Test/Unit/Block/Product/ProductList/UpsellTest.php index 03f3c83d87dcb..f3aa3f182d198 100644 --- a/app/code/Magento/Catalog/Test/Unit/Block/Product/ProductList/UpsellTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Block/Product/ProductList/UpsellTest.php @@ -5,17 +5,21 @@ */ namespace Magento\Catalog\Test\Unit\Block\Product\ProductList; +use Magento\Catalog\Block\Product\ProductList\Upsell as UpsellBlock; +use Magento\Catalog\Model\Product; + class UpsellTest extends \PHPUnit\Framework\TestCase { + const STUB_EMPTY_ARRAY = []; /** - * @var \Magento\Catalog\Block\Product\ProductList\Upsell + * @var UpsellBlock */ protected $block; protected function setUp() { $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); - $this->block = $objectManager->getObject(\Magento\Catalog\Block\Product\ProductList\Upsell::class); + $this->block = $objectManager->getObject(UpsellBlock::class); } protected function tearDown() @@ -26,10 +30,10 @@ protected function tearDown() public function testGetIdentities() { $productTag = ['compare_item_1']; - $product = $this->createMock(\Magento\Catalog\Model\Product::class); + $product = $this->createMock(Product::class); $product->expects($this->once())->method('getIdentities')->will($this->returnValue($productTag)); - $itemsCollection = new \ReflectionProperty(\Magento\Catalog\Block\Product\ProductList\Upsell::class, '_items'); + $itemsCollection = new \ReflectionProperty(UpsellBlock::class, '_items'); $itemsCollection->setAccessible(true); $itemsCollection->setValue($this->block, [$product]); @@ -38,4 +42,32 @@ public function testGetIdentities() $this->block->getIdentities() ); } + + public function testGetIdentitiesWhenItemGetIdentitiesReturnEmptyArray() + { + $product = $this->createMock(Product::class); + $product->expects($this->once())->method('getIdentities') + ->willReturn(self::STUB_EMPTY_ARRAY); + + $itemsCollection = new \ReflectionProperty(UpsellBlock::class, '_items'); + $itemsCollection->setAccessible(true); + $itemsCollection->setValue($this->block, [$product]); + + $this->assertEquals( + self::STUB_EMPTY_ARRAY, + $this->block->getIdentities() + ); + } + + public function testGetIdentitiesWhenGetItemsReturnEmptyArray() + { + $itemsCollection = new \ReflectionProperty(UpsellBlock::class, '_items'); + $itemsCollection->setAccessible(true); + $itemsCollection->setValue($this->block, self::STUB_EMPTY_ARRAY); + + $this->assertEquals( + self::STUB_EMPTY_ARRAY, + $this->block->getIdentities() + ); + } } diff --git a/app/code/Magento/CatalogInventory/Model/StockIndex.php b/app/code/Magento/CatalogInventory/Model/StockIndex.php index 41db057cf149c..ad0cff43c6ac9 100644 --- a/app/code/Magento/CatalogInventory/Model/StockIndex.php +++ b/app/code/Magento/CatalogInventory/Model/StockIndex.php @@ -6,16 +6,20 @@ namespace Magento\CatalogInventory\Model; +use Magento\Catalog\Model\Product; use Magento\Catalog\Model\Product\Type as ProductType; use Magento\Catalog\Model\Product\Website as ProductWebsite; -use Magento\Catalog\Model\ProductFactory; use Magento\CatalogInventory\Api\StockIndexInterface; +use Magento\CatalogInventory\Model\ResourceModel\Stock\Status as StockStatusResourceModel; use Magento\CatalogInventory\Model\Spi\StockRegistryProviderInterface; use Magento\Catalog\Api\ProductRepositoryInterface; use Magento\Catalog\Model\Product\Attribute\Source\Status; +use Magento\Framework\App\ObjectManager; +use Magento\Store\Model\Website; /** - * Class StockIndex + * Index responsible for Stock + * * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ class StockIndex implements StockIndexInterface @@ -31,7 +35,7 @@ class StockIndex implements StockIndexInterface protected $productRepository; /** - * @var \Magento\CatalogInventory\Model\ResourceModel\Stock\Status + * @var StockStatusResourceModel */ protected $stockStatusResource; @@ -47,6 +51,11 @@ class StockIndex implements StockIndexInterface */ protected $websites; + /** + * @var ProductWebsite + */ + private $productWebsite; + /** * Product Type Instances cache * @@ -88,7 +97,7 @@ public function rebuild($productId = null, $scopeId = null) } else { $lastProductId = 0; while (true) { - /** @var \Magento\CatalogInventory\Model\ResourceModel\Stock\Status $resource */ + /** @var StockStatusResourceModel $resource */ $resource = $this->getStockStatusResource(); $productCollection = $resource->getProductCollection($lastProductId); if (!$productCollection) { @@ -115,7 +124,7 @@ public function updateProductStockStatus($productId, $websiteId) { $item = $this->stockRegistryProvider->getStockItem($productId, $websiteId); - $status = \Magento\CatalogInventory\Model\Stock\Status::STATUS_IN_STOCK; + $status = Stock\Status::STATUS_IN_STOCK; $qty = 0; if ($item->getItemId()) { $status = $item->getIsInStock(); @@ -132,16 +141,16 @@ public function updateProductStockStatus($productId, $websiteId) * @param int $websiteId * @param int $qty * @param int $status - * @return $this + * @return void * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ protected function processChildren( $productId, $websiteId, $qty = 0, - $status = \Magento\CatalogInventory\Model\Stock\Status::STATUS_IN_STOCK + $status = Stock\Status::STATUS_IN_STOCK ) { - if ($status == \Magento\CatalogInventory\Model\Stock\Status::STATUS_OUT_OF_STOCK) { + if ($status == Stock\Status::STATUS_OUT_OF_STOCK) { $this->getStockStatusResource()->saveProductStatus($productId, $status, $qty, $websiteId); return; } @@ -150,20 +159,22 @@ protected function processChildren( $websitesWithStores = $this->getWebsitesWithDefaultStores($websiteId); foreach (array_keys($websitesWithStores) as $websiteId) { - /* @var $website \Magento\Store\Model\Website */ + /* @var $website Website */ $statuses[$websiteId] = $status; } - /** @var \Magento\Catalog\Model\Product $product */ + /** @var Product $product */ $product = $this->productRepository->getById($productId); $typeInstance = $product->getTypeInstance(); $requiredChildrenIds = $typeInstance->getChildrenIds($productId, true); if ($requiredChildrenIds) { - $childrenIds = []; + $childrenIds = [[]]; foreach ($requiredChildrenIds as $groupedChildrenIds) { - $childrenIds = array_merge($childrenIds, $groupedChildrenIds); + $childrenIds[] = $groupedChildrenIds; } + $childrenIds = array_merge(...$childrenIds); + $childrenWebsites = $this->productWebsite->getWebsites($childrenIds); foreach ($websitesWithStores as $websiteId => $storeId) { $childrenStatus = $this->getStockStatusResource()->getProductStatus($childrenIds, $storeId); @@ -177,7 +188,7 @@ protected function processChildren( && in_array($websiteId, $childrenWebsites[$childId]) && $childrenStatus[$childId] == Status::STATUS_ENABLED && isset($childrenStock[$childId]) - && $childrenStock[$childId] == \Magento\CatalogInventory\Model\Stock\Status::STATUS_IN_STOCK + && $childrenStock[$childId] == Stock\Status::STATUS_IN_STOCK ) { $optionStatus = true; } @@ -196,12 +207,12 @@ protected function processChildren( * Retrieve website models * * @param int|null $websiteId - * @return array + * @return Website[] */ protected function getWebsitesWithDefaultStores($websiteId = null) { if ($this->websites === null) { - /** @var \Magento\CatalogInventory\Model\ResourceModel\Stock\Status $resource */ + /** @var StockStatusResourceModel $resource */ $resource = $this->getStockStatusResource(); $this->websites = $resource->getWebsiteStores(); } @@ -217,23 +228,25 @@ protected function getWebsitesWithDefaultStores($websiteId = null) * * @param int $productId * @param int $websiteId - * @return $this + * @return void */ protected function processParents($productId, $websiteId) { - $parentIds = []; + $parentIds = [[]]; foreach ($this->getProductTypeInstances() as $typeInstance) { - /* @var $typeInstance AbstractType */ - $parentIds = array_merge($parentIds, $typeInstance->getParentIdsByChild($productId)); + /* @var ProductType\AbstractType $typeInstance */ + $parentIds[] = $typeInstance->getParentIdsByChild($productId); } - if (!$parentIds) { - return $this; + $parentIds = array_merge(...$parentIds); + + if (empty($parentIds)) { + return; } foreach ($parentIds as $parentId) { $item = $this->stockRegistryProvider->getStockItem($parentId, $websiteId); - $status = \Magento\CatalogInventory\Model\Stock\Status::STATUS_IN_STOCK; + $status = Stock\Status::STATUS_IN_STOCK; $qty = 0; if ($item->getItemId()) { $status = $item->getIsInStock(); @@ -244,10 +257,9 @@ protected function processParents($productId, $websiteId) } /** - * Retrieve Product Type Instances - * as key - type code, value - instance model + * Retrieve Product Type Instances as key - type code, value - instance model * - * @return array + * @return ProductType\AbstractType[] */ protected function getProductTypeInstances() { @@ -262,14 +274,14 @@ protected function getProductTypeInstances() } /** - * @return \Magento\CatalogInventory\Model\ResourceModel\Stock\Status + * Returns ResourceModel for Stock Status + * + * @return StockStatusResourceModel */ protected function getStockStatusResource() { if (empty($this->stockStatusResource)) { - $this->stockStatusResource = \Magento\Framework\App\ObjectManager::getInstance()->get( - \Magento\CatalogInventory\Model\ResourceModel\Stock\Status::class - ); + $this->stockStatusResource = ObjectManager::getInstance()->get(StockStatusResourceModel::class); } return $this->stockStatusResource; } diff --git a/app/code/Magento/CatalogSearch/Model/Search/FiltersExtractor.php b/app/code/Magento/CatalogSearch/Model/Search/FiltersExtractor.php index 55c8582979912..63d7ee0e6e4c0 100644 --- a/app/code/Magento/CatalogSearch/Model/Search/FiltersExtractor.php +++ b/app/code/Magento/CatalogSearch/Model/Search/FiltersExtractor.php @@ -10,11 +10,10 @@ use Magento\Framework\Search\Request\Filter\BoolExpression; /** - * Class FiltersExtractor * Extracts filters from QueryInterface * - * @deprecated - * @see \Magento\ElasticSearch + * @deprecated Use Magento\Elasticsearch implementation of QueryInterface + * @see \Magento\Elasticsearch */ class FiltersExtractor { @@ -26,19 +25,19 @@ class FiltersExtractor */ public function extractFiltersFromQuery(QueryInterface $query) { - $filters = []; + $filters = [[]]; switch ($query->getType()) { case QueryInterface::TYPE_BOOL: /** @var \Magento\Framework\Search\Request\Query\BoolExpression $query */ foreach ($query->getMust() as $subQuery) { - $filters = array_merge($filters, $this->extractFiltersFromQuery($subQuery)); + $filters[] = $this->extractFiltersFromQuery($subQuery); } foreach ($query->getShould() as $subQuery) { - $filters = array_merge($filters, $this->extractFiltersFromQuery($subQuery)); + $filters[] = $this->extractFiltersFromQuery($subQuery); } foreach ($query->getMustNot() as $subQuery) { - $filters = array_merge($filters, $this->extractFiltersFromQuery($subQuery)); + $filters[] = $this->extractFiltersFromQuery($subQuery); } break; @@ -46,9 +45,9 @@ public function extractFiltersFromQuery(QueryInterface $query) /** @var Filter $query */ $filter = $query->getReference(); if (FilterInterface::TYPE_BOOL === $filter->getType()) { - $filters = array_merge($filters, $this->getFiltersFromBoolFilter($filter)); + $filters[] = $this->getFiltersFromBoolFilter($filter); } else { - $filters[] = $filter; + $filters[] = [$filter]; } break; @@ -56,39 +55,41 @@ public function extractFiltersFromQuery(QueryInterface $query) break; } - return $filters; + return array_merge(...$filters); } /** + * Returns list of filters from Bool filter + * * @param BoolExpression $boolExpression * @return FilterInterface[] */ private function getFiltersFromBoolFilter(BoolExpression $boolExpression) { - $filters = []; + $filters = [[]]; /** @var BoolExpression $filter */ foreach ($boolExpression->getMust() as $filter) { if ($filter->getType() === FilterInterface::TYPE_BOOL) { - $filters = array_merge($filters, $this->getFiltersFromBoolFilter($filter)); + $filters[] = $this->getFiltersFromBoolFilter($filter); } else { - $filters[] = $filter; + $filters[] = [$filter]; } } foreach ($boolExpression->getShould() as $filter) { if ($filter->getType() === FilterInterface::TYPE_BOOL) { - $filters = array_merge($filters, $this->getFiltersFromBoolFilter($filter)); + $filters[] = $this->getFiltersFromBoolFilter($filter); } else { - $filters[] = $filter; + $filters[] = [$filter]; } } foreach ($boolExpression->getMustNot() as $filter) { if ($filter->getType() === FilterInterface::TYPE_BOOL) { - $filters = array_merge($filters, $this->getFiltersFromBoolFilter($filter)); + $filters[] = $this->getFiltersFromBoolFilter($filter); } else { - $filters[] = $filter; + $filters[] = [$filter]; } } - return $filters; + return array_merge(...$filters); } } diff --git a/app/code/Magento/CatalogUrlRewrite/Model/Category/Plugin/Store/Group.php b/app/code/Magento/CatalogUrlRewrite/Model/Category/Plugin/Store/Group.php index 1dbfad6cf5219..308b82e38c43a 100644 --- a/app/code/Magento/CatalogUrlRewrite/Model/Category/Plugin/Store/Group.php +++ b/app/code/Magento/CatalogUrlRewrite/Model/Category/Plugin/Store/Group.php @@ -5,6 +5,7 @@ */ namespace Magento\CatalogUrlRewrite\Model\Category\Plugin\Store; +use Magento\Store\Model\ResourceModel\Group as StoreGroup; use Magento\UrlRewrite\Model\UrlPersistInterface; use Magento\UrlRewrite\Service\V1\Data\UrlRewrite; use Magento\Catalog\Model\CategoryFactory; @@ -16,37 +17,39 @@ use Magento\Framework\Model\AbstractModel; /** + * Generate Product and Category URLs + * * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ class Group { /** - * @var \Magento\UrlRewrite\Model\UrlPersistInterface + * @var UrlPersistInterface */ protected $urlPersist; /** - * @var \Magento\Catalog\Model\CategoryFactory + * @var CategoryFactory */ protected $categoryFactory; /** - * @var \Magento\Catalog\Model\ProductFactory + * @var ProductFactory */ protected $productFactory; /** - * @var \Magento\CatalogUrlRewrite\Model\CategoryUrlRewriteGenerator + * @var CategoryUrlRewriteGenerator */ protected $categoryUrlRewriteGenerator; /** - * @var \Magento\CatalogUrlRewrite\Model\ProductUrlRewriteGenerator + * @var ProductUrlRewriteGenerator */ protected $productUrlRewriteGenerator; /** - * @var \Magento\Store\Model\StoreManagerInterface + * @var StoreManagerInterface */ protected $storeManager; @@ -77,15 +80,15 @@ public function __construct( /** * Perform updating url for categories and products assigned to the group * - * @param \Magento\Store\Model\ResourceModel\Group $subject - * @param \Magento\Store\Model\ResourceModel\Group $result + * @param StoreGroup $subject + * @param StoreGroup $result * @param AbstractModel $group - * @return \Magento\Store\Model\ResourceModel\Group + * @return StoreGroup * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function afterSave( - \Magento\Store\Model\ResourceModel\Group $subject, - \Magento\Store\Model\ResourceModel\Group $result, + StoreGroup $subject, + StoreGroup $result, AbstractModel $group ) { if (!$group->isObjectNew() @@ -118,7 +121,7 @@ public function afterSave( */ protected function generateProductUrls($websiteId, $originWebsiteId) { - $urls = []; + $urls = [[]]; $websiteIds = $websiteId != $originWebsiteId ? [$websiteId, $originWebsiteId] : [$websiteId]; @@ -130,33 +133,30 @@ protected function generateProductUrls($websiteId, $originWebsiteId) foreach ($collection as $product) { /** @var \Magento\Catalog\Model\Product $product */ $product->setStoreId(Store::DEFAULT_STORE_ID); - $urls = array_merge( - $urls, - $this->productUrlRewriteGenerator->generate($product) - ); + $urls[] = $this->productUrlRewriteGenerator->generate($product); } - return $urls; + return array_merge(...$urls); } /** + * Generate url rewrites for categories assigned to store + * * @param int $rootCategoryId * @param array $storeIds * @return array */ 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 */ $category->setStoreId(Store::DEFAULT_STORE_ID); $category->setStoreIds($storeIds); - $urls = array_merge( - $urls, - $this->categoryUrlRewriteGenerator->generate($category) - ); + $urls[] = $this->categoryUrlRewriteGenerator->generate($category); } - return $urls; + + return array_merge(...$urls); } } diff --git a/app/code/Magento/CatalogWidget/Block/Product/ProductsList.php b/app/code/Magento/CatalogWidget/Block/Product/ProductsList.php index 4a75c806aa37b..82fae8fc3875d 100644 --- a/app/code/Magento/CatalogWidget/Block/Product/ProductsList.php +++ b/app/code/Magento/CatalogWidget/Block/Product/ProductsList.php @@ -125,7 +125,7 @@ class ProductsList extends AbstractProduct implements BlockInterface, IdentityIn private $urlEncoder; /** - * @var \Magento\Framework\View\Element\RendererList + * @var RendererList */ private $rendererListBlock; @@ -194,14 +194,12 @@ protected function _construct() ->addColumnCountLayoutDepend('2columns-right', 4) ->addColumnCountLayoutDepend('3columns', 3); - $this->addData( - [ - 'cache_lifetime' => 86400, - 'cache_tags' => [ - Product::CACHE_TAG, - ], - ] - ); + $this->addData([ + 'cache_lifetime' => 86400, + 'cache_tags' => [ + Product::CACHE_TAG, + ], + ]); } /** @@ -506,14 +504,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[] = $product->getIdentities(); } } } + $identities = array_merge(...$identities); return $identities ?: [Product::CACHE_TAG]; } diff --git a/app/code/Magento/CheckoutAgreements/Model/AgreementsValidator.php b/app/code/Magento/CheckoutAgreements/Model/AgreementsValidator.php index 8d25ba88c0f82..2643e69ba1efd 100644 --- a/app/code/Magento/CheckoutAgreements/Model/AgreementsValidator.php +++ b/app/code/Magento/CheckoutAgreements/Model/AgreementsValidator.php @@ -5,13 +5,15 @@ */ namespace Magento\CheckoutAgreements\Model; +use Magento\Checkout\Api\AgreementsValidatorInterface; + /** - * Class AgreementsValidator + * Validator for Checkout Agreements */ -class AgreementsValidator implements \Magento\Checkout\Api\AgreementsValidatorInterface +class AgreementsValidator implements AgreementsValidatorInterface { /** - * @var \Magento\CheckoutAgreements\Model\AgreementsProviderInterface[] + * @var AgreementsProviderInterface[] */ protected $agreementsProviders; @@ -33,11 +35,13 @@ public function __construct($list = null) public function isValid($agreementIds = []) { $agreementIds = $agreementIds === null ? [] : $agreementIds; - $requiredAgreements = []; + $requiredAgreements = [[]]; foreach ($this->agreementsProviders as $agreementsProvider) { - $requiredAgreements = array_merge($requiredAgreements, $agreementsProvider->getRequiredAgreementIds()); + $requiredAgreements[] = $agreementsProvider->getRequiredAgreementIds(); } - $agreementsDiff = array_diff($requiredAgreements, $agreementIds); + + $agreementsDiff = array_diff(array_merge(...$requiredAgreements), $agreementIds); + return empty($agreementsDiff); } } diff --git a/app/code/Magento/CurrencySymbol/Model/System/Currencysymbol.php b/app/code/Magento/CurrencySymbol/Model/System/Currencysymbol.php index 6c7019986cce0..d48df02d9de27 100644 --- a/app/code/Magento/CurrencySymbol/Model/System/Currencysymbol.php +++ b/app/code/Magento/CurrencySymbol/Model/System/Currencysymbol.php @@ -292,7 +292,8 @@ protected function _unserializeStoreConfig($configPath, $storeId = null) */ protected function getAllowedCurrencies() { - $allowedCurrencies = explode( + $allowedCurrencies = [[]]; + $allowedCurrencies[] = explode( self::ALLOWED_CURRENCIES_CONFIG_SEPARATOR, $this->_scopeConfig->getValue( self::XML_PATH_ALLOWED_CURRENCIES, @@ -318,23 +319,17 @@ protected function getAllowedCurrencies() if (!$websiteShow) { $websiteShow = true; $websiteSymbols = $website->getConfig(self::XML_PATH_ALLOWED_CURRENCIES); - $allowedCurrencies = array_merge( - $allowedCurrencies, - explode(self::ALLOWED_CURRENCIES_CONFIG_SEPARATOR, $websiteSymbols) - ); + $allowedCurrencies[] = explode(self::ALLOWED_CURRENCIES_CONFIG_SEPARATOR, $websiteSymbols); } $storeSymbols = $this->_scopeConfig->getValue( self::XML_PATH_ALLOWED_CURRENCIES, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $store ); - $allowedCurrencies = array_merge( - $allowedCurrencies, - explode(self::ALLOWED_CURRENCIES_CONFIG_SEPARATOR, $storeSymbols) - ); + $allowedCurrencies[] = explode(self::ALLOWED_CURRENCIES_CONFIG_SEPARATOR, $storeSymbols); } } } - return array_unique($allowedCurrencies); + return array_unique(array_merge(...$allowedCurrencies)); } } diff --git a/app/code/Magento/CurrencySymbol/Test/Unit/Observer/CurrencyDisplayOptionsTest.php b/app/code/Magento/CurrencySymbol/Test/Unit/Observer/CurrencyDisplayOptionsTest.php index dd0d7ffc8cc68..ae8c12c2019b8 100644 --- a/app/code/Magento/CurrencySymbol/Test/Unit/Observer/CurrencyDisplayOptionsTest.php +++ b/app/code/Magento/CurrencySymbol/Test/Unit/Observer/CurrencyDisplayOptionsTest.php @@ -6,6 +6,7 @@ namespace Magento\CurrencySymbol\Test\Unit\Observer; use Magento\CurrencySymbol\Model\System\CurrencysymbolFactory; +use Magento\Framework\Locale\Currency; /** * Test for \Magento\CurrencySymbol\Observer\CurrencyDisplayOptions @@ -65,7 +66,7 @@ protected function setUp() public function testCurrencyDisplayOptionsEmpty() { $baseData = [ - \Magento\Framework\Locale\Currency::CURRENCY_OPTION_NAME => 'US Dollar' + Currency::CURRENCY_OPTION_NAME => 'US Dollar' ]; $sampleCurrencyOptionObject = new \Magento\Framework\DataObject($baseData); @@ -83,7 +84,7 @@ public function testCurrencyDisplayOptionsEmpty() public function testCurrencyDisplayOptions() { $baseData = [ - \Magento\Framework\Locale\Currency::CURRENCY_OPTION_NAME => 'US Dollar' + Currency::CURRENCY_OPTION_NAME => 'US Dollar' ]; $sampleCurrencyOptionObject = new \Magento\Framework\DataObject($baseData); $sampleCurrency = 'USD'; @@ -92,9 +93,9 @@ public function testCurrencyDisplayOptions() $expectedCurrencyOptions = array_merge( $baseData, [ - \Magento\Framework\Locale\Currency::CURRENCY_OPTION_NAME => 'US Dollar', - \Magento\Framework\Locale\Currency::CURRENCY_OPTION_SYMBOL => $sampleCurrencySymbol, - \Magento\Framework\Locale\Currency::CURRENCY_OPTION_DISPLAY => \Magento\Framework\Currency::USE_SYMBOL + Currency::CURRENCY_OPTION_NAME => 'US Dollar', + Currency::CURRENCY_OPTION_SYMBOL => $sampleCurrencySymbol, + Currency::CURRENCY_OPTION_DISPLAY => \Magento\Framework\Currency::USE_SYMBOL ] ); diff --git a/app/code/Magento/Customer/Model/Address/CompositeValidator.php b/app/code/Magento/Customer/Model/Address/CompositeValidator.php index 1d16a929532f5..4c77f10c11de4 100644 --- a/app/code/Magento/Customer/Model/Address/CompositeValidator.php +++ b/app/code/Magento/Customer/Model/Address/CompositeValidator.php @@ -30,11 +30,11 @@ public function __construct( */ public function validate(AbstractAddress $address) { - $errors = []; + $errors = [[]]; foreach ($this->validators as $validator) { - $errors = array_merge($errors, $validator->validate($address)); + $errors[] = $validator->validate($address); } - return $errors; + return array_merge(...$errors); } } diff --git a/app/code/Magento/Customer/Model/Metadata/Form.php b/app/code/Magento/Customer/Model/Metadata/Form.php index 6df969f625376..85637ebf508b8 100644 --- a/app/code/Magento/Customer/Model/Metadata/Form.php +++ b/app/code/Magento/Customer/Model/Metadata/Form.php @@ -9,6 +9,8 @@ use Magento\Customer\Api\CustomerMetadataInterface; /** + * Customer Form metadata model + * * @api * @since 100.0.2 */ @@ -361,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_merge($messages, (array)$errorMessages); + $messages[] = (array)$errorMessages; } - return $messages; + return array_merge(...$messages); } return true; } diff --git a/app/code/Magento/Customer/Model/ResourceModel/Address/Attribute/Source/CountryWithWebsites.php b/app/code/Magento/Customer/Model/ResourceModel/Address/Attribute/Source/CountryWithWebsites.php index ce6278b446302..020067570efb4 100644 --- a/app/code/Magento/Customer/Model/ResourceModel/Address/Attribute/Source/CountryWithWebsites.php +++ b/app/code/Magento/Customer/Model/ResourceModel/Address/Attribute/Source/CountryWithWebsites.php @@ -12,18 +12,28 @@ namespace Magento\Customer\Model\ResourceModel\Address\Attribute\Source; use Magento\Customer\Model\Config\Share; +use Magento\Customer\Model\Config\Share as CustomerShareConfig; use Magento\Directory\Model\AllowedCountries; +use Magento\Directory\Model\ResourceModel\Country\Collection as CountryCollection; +use Magento\Directory\Model\ResourceModel\Country\CollectionFactory as CountryCollectionFactory; +use Magento\Eav\Model\Entity\Attribute\Source\Table; +use Magento\Eav\Model\ResourceModel\Entity\Attribute\Option\CollectionFactory as OptionCollectionFactory; +use Magento\Eav\Model\ResourceModel\Entity\Attribute\OptionFactory as AttrubuteOptionFactory; use Magento\Store\Model\ScopeInterface; +use Magento\Store\Model\StoreManagerInterface; -class CountryWithWebsites extends \Magento\Eav\Model\Entity\Attribute\Source\Table +/** + * Return allowed countries for specified website + */ +class CountryWithWebsites extends Table { /** - * @var \Magento\Directory\Model\ResourceModel\Country\CollectionFactory + * @var CountryCollectionFactory */ private $countriesFactory; /** - * @var \Magento\Directory\Model\AllowedCountries + * @var AllowedCountries */ private $allowedCountriesReader; @@ -33,7 +43,7 @@ class CountryWithWebsites extends \Magento\Eav\Model\Entity\Attribute\Source\Tab private $options; /** - * @var \Magento\Store\Model\StoreManagerInterface + * @var StoreManagerInterface */ private $storeManager; @@ -43,21 +53,20 @@ class CountryWithWebsites extends \Magento\Eav\Model\Entity\Attribute\Source\Tab private $shareConfig; /** - * CountryWithWebsites constructor. - * @param \Magento\Eav\Model\ResourceModel\Entity\Attribute\Option\CollectionFactory $attrOptionCollectionFactory - * @param \Magento\Eav\Model\ResourceModel\Entity\Attribute\OptionFactory $attrOptionFactory - * @param \Magento\Directory\Model\ResourceModel\Country\CollectionFactory $countriesFactory + * @param OptionCollectionFactory $attrOptionCollectionFactory + * @param AttrubuteOptionFactory $attrOptionFactory + * @param CountryCollectionFactory $countriesFactory * @param AllowedCountries $allowedCountriesReader - * @param \Magento\Store\Model\StoreManagerInterface $storeManager + * @param StoreManagerInterface $storeManager * @param Share $shareConfig */ public function __construct( - \Magento\Eav\Model\ResourceModel\Entity\Attribute\Option\CollectionFactory $attrOptionCollectionFactory, - \Magento\Eav\Model\ResourceModel\Entity\Attribute\OptionFactory $attrOptionFactory, - \Magento\Directory\Model\ResourceModel\Country\CollectionFactory $countriesFactory, - \Magento\Directory\Model\AllowedCountries $allowedCountriesReader, - \Magento\Store\Model\StoreManagerInterface $storeManager, - \Magento\Customer\Model\Config\Share $shareConfig + OptionCollectionFactory $attrOptionCollectionFactory, + AttrubuteOptionFactory $attrOptionFactory, + CountryCollectionFactory $countriesFactory, + AllowedCountries $allowedCountriesReader, + StoreManagerInterface $storeManager, + CustomerShareConfig $shareConfig ) { $this->countriesFactory = $countriesFactory; $this->allowedCountriesReader = $allowedCountriesReader; @@ -72,19 +81,22 @@ public function __construct( public function getAllOptions($withEmpty = true, $defaultValues = false) { if (!$this->options) { - $allowedCountries = []; $websiteIds = []; if (!$this->shareConfig->isGlobalScope()) { + $allowedCountries = [[]]; + foreach ($this->storeManager->getWebsites() as $website) { $countries = $this->allowedCountriesReader ->getAllowedCountries(ScopeInterface::SCOPE_WEBSITE, $website->getId()); - $allowedCountries = array_merge($allowedCountries, $countries); + $allowedCountries[] = $countries; foreach ($countries as $countryCode) { $websiteIds[$countryCode][] = $website->getId(); } } + + $allowedCountries = array_unique(array_merge(...$allowedCountries)); } else { $allowedCountries = $this->allowedCountriesReader->getAllowedCountries(); } @@ -106,7 +118,7 @@ public function getAllOptions($withEmpty = true, $defaultValues = false) /** * Create Countries Collection with all countries * - * @return \Magento\Directory\Model\ResourceModel\Country\Collection + * @return CountryCollection */ private function createCountriesCollection() { diff --git a/app/code/Magento/CustomerImportExport/Model/Import/Address.php b/app/code/Magento/CustomerImportExport/Model/Import/Address.php index 1a8859d5bd7bf..55c58282bcae4 100644 --- a/app/code/Magento/CustomerImportExport/Model/Import/Address.php +++ b/app/code/Magento/CustomerImportExport/Model/Import/Address.php @@ -3,6 +3,7 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ + namespace Magento\CustomerImportExport\Model\Import; use Magento\Customer\Model\ResourceModel\Address\Attribute\Source\CountryWithWebsites as CountryWithWebsitesSource; @@ -224,7 +225,11 @@ class Address extends AbstractCustomer * @array */ protected $validColumnNames = [ - "region_id", "vat_is_valid", "vat_request_date", "vat_request_id", "vat_request_success" + "region_id", + "vat_is_valid", + "vat_request_date", + "vat_request_id", + "vat_request_success" ]; /** @@ -507,11 +512,12 @@ public function validateData() protected function _importData() { //Preparing data for mass validation/import. - $rows = []; + $rows = [[]]; while ($bunch = $this->_dataSourceModel->getNextBunch()) { - $rows = array_merge($rows, $bunch); + $rows[] = $bunch; } - $this->prepareCustomerData($rows); + + $this->prepareCustomerData(array_merge(...$rows)); unset($bunch, $rows); $this->_dataSourceModel->getIterator()->rewind(); @@ -586,7 +592,7 @@ protected function _mergeEntityAttributes(array $newAttributes, array $attribute * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ - protected function _prepareDataForUpdate(array $rowData):array + protected function _prepareDataForUpdate(array $rowData): array { $email = strtolower($rowData[self::COLUMN_EMAIL]); $customerId = $this->_getCustomerId($email, $rowData[self::COLUMN_WEBSITE]); @@ -636,7 +642,7 @@ protected function _prepareDataForUpdate(array $rowData):array if ($attributeParams['is_static']) { $entityRow[$attributeAlias] = $value; } else { - $attributes[$attributeParams['table']][$addressId][$attributeParams['id']]= $value; + $attributes[$attributeParams['table']][$addressId][$attributeParams['id']] = $value; } } } diff --git a/app/code/Magento/CustomerImportExport/Model/Import/Customer.php b/app/code/Magento/CustomerImportExport/Model/Import/Customer.php index 5e5f309915d99..cf3fa6b0b521f 100644 --- a/app/code/Magento/CustomerImportExport/Model/Import/Customer.php +++ b/app/code/Magento/CustomerImportExport/Model/Import/Customer.php @@ -502,8 +502,8 @@ protected function _importData() { while ($bunch = $this->_dataSourceModel->getNextBunch()) { $this->prepareCustomerData($bunch); - $entitiesToCreate = []; - $entitiesToUpdate = []; + $entitiesToCreate = [[]]; + $entitiesToUpdate = [[]]; $entitiesToDelete = []; $attributesToSave = []; @@ -523,10 +523,10 @@ protected function _importData() ); } elseif ($this->getBehavior($rowData) == \Magento\ImportExport\Model\Import::BEHAVIOR_ADD_UPDATE) { $processedData = $this->_prepareDataForUpdate($rowData); - // phpcs:disable Magento2.Performance.ForeachArrayMerge - $entitiesToCreate = array_merge($entitiesToCreate, $processedData[self::ENTITIES_TO_CREATE_KEY]); - $entitiesToUpdate = array_merge($entitiesToUpdate, $processedData[self::ENTITIES_TO_UPDATE_KEY]); - // phpcs:enable + + $entitiesToCreate[] = $processedData[self::ENTITIES_TO_CREATE_KEY]; + $entitiesToUpdate[] = $processedData[self::ENTITIES_TO_UPDATE_KEY]; + foreach ($processedData[self::ATTRIBUTES_TO_SAVE_KEY] as $tableName => $customerAttributes) { if (!isset($attributesToSave[$tableName])) { $attributesToSave[$tableName] = []; @@ -536,6 +536,10 @@ protected function _importData() } } } + + $entitiesToCreate = array_merge(...$entitiesToCreate); + $entitiesToUpdate = array_merge(...$entitiesToUpdate); + $this->updateItemsCounterStats($entitiesToCreate, $entitiesToUpdate, $entitiesToDelete); /** * Save prepared data diff --git a/app/code/Magento/Deploy/Package/Package.php b/app/code/Magento/Deploy/Package/Package.php index 423f3072c4620..4821d32454675 100644 --- a/app/code/Magento/Deploy/Package/Package.php +++ b/app/code/Magento/Deploy/Package/Package.php @@ -443,12 +443,11 @@ public function getResultMap() */ public function getParentMap() { - $map = []; + $map = [[]]; foreach ($this->getParentPackages() as $parentPackage) { - // phpcs:ignore Magento2.Performance.ForeachArrayMerge.ForeachArrayMerge - $map = array_merge($map, $parentPackage->getMap()); + $map[] = $parentPackage->getMap(); } - return $map; + return array_merge(...$map); } /** @@ -462,10 +461,8 @@ public function getParentFiles($type = null) $files = [[]]; foreach ($this->getParentPackages() as $parentPackage) { if ($type === null) { - // phpcs:ignore Magento2.Performance.ForeachArrayMerge.ForeachArrayMerge $files[] = $parentPackage->getFiles(); } else { - // phpcs:ignore Magento2.Performance.ForeachArrayMerge.ForeachArrayMerge $files[] = $parentPackage->getFilesByType($type); } } diff --git a/app/code/Magento/Deploy/Package/Processor/PreProcessor/Css.php b/app/code/Magento/Deploy/Package/Processor/PreProcessor/Css.php index b3461e3ab4a22..42775a2e2f6bf 100644 --- a/app/code/Magento/Deploy/Package/Processor/PreProcessor/Css.php +++ b/app/code/Magento/Deploy/Package/Processor/PreProcessor/Css.php @@ -3,12 +3,14 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ + namespace Magento\Deploy\Package\Processor\PreProcessor; use Magento\Deploy\Console\DeployStaticOptions; use Magento\Deploy\Package\Package; use Magento\Deploy\Package\PackageFile; use Magento\Deploy\Package\Processor\ProcessorInterface; +use Magento\Framework\Css\PreProcessor\Instruction\Import; use Magento\Framework\Filesystem; use Magento\Framework\Filesystem\Directory\ReadInterface; use Magento\Framework\App\Filesystem\DirectoryList; @@ -92,8 +94,7 @@ public function process(Package $package, array $options) } /** - * Checks if there are imports of CSS files or images within the given CSS file - * which exists in the current package + * Checks if there are imports of CSS files or images within the given CSS file which exists in the current package * * @param PackageFile $parentFile * @param Package $package @@ -126,6 +127,7 @@ private function hasOverrides(PackageFile $parentFile, Package $package) * @param string $filePath * @param string $fullPath * @return void + * phpcs:disable Magento2.Functions.DiscouragedFunction */ private function buildMap($packagePath, $filePath, $fullPath) { @@ -141,11 +143,7 @@ private function buildMap($packagePath, $filePath, $fullPath) $packagePath . '/' . pathinfo($filePath, PATHINFO_DIRNAME) . '/' . $matchContent['path'] ); }; - preg_replace_callback( - \Magento\Framework\Css\PreProcessor\Instruction\Import::REPLACE_PATTERN, - $callback, - $content - ); + preg_replace_callback(Import::REPLACE_PATTERN, $callback, $content); preg_match_all(CssResolver::REGEX_CSS_RELATIVE_URLS, $content, $matches); if (!empty($matches[0]) && !empty($matches[1])) { @@ -177,6 +175,7 @@ private function buildMap($packagePath, $filePath, $fullPath) * * @param string $fileName * @return array + * phpcs:disable Magento2.Performance.ForeachArrayMerge */ private function collectFileMap($fileName) { diff --git a/app/code/Magento/Developer/Console/Command/XmlCatalogGenerateCommand.php b/app/code/Magento/Developer/Console/Command/XmlCatalogGenerateCommand.php index 323b8e1016291..9e473ccaa2d92 100644 --- a/app/code/Magento/Developer/Console/Command/XmlCatalogGenerateCommand.php +++ b/app/code/Magento/Developer/Console/Command/XmlCatalogGenerateCommand.php @@ -6,7 +6,12 @@ namespace Magento\Developer\Console\Command; +use Magento\Developer\Model\XmlCatalog\Format\FormatInterface; +use Magento\Framework\App\Utility\Files; +use Magento\Framework\Config\Dom\UrnResolver; +use Magento\Framework\Console\Cli; use Magento\Framework\Exception\InputException; +use Magento\Framework\Filesystem\Directory\ReadFactory; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; @@ -34,37 +39,37 @@ class XmlCatalogGenerateCommand extends Command const IDE_FILE_PATH_ARGUMENT = 'path'; /** - * @var \Magento\Framework\App\Utility\Files + * @var Files */ private $filesUtility; /** - * @var \Magento\Framework\Config\Dom\UrnResolver + * @var UrnResolver */ private $urnResolver; /** - * @var \Magento\Framework\Filesystem\Directory\ReadFactory + * @var ReadFactory */ private $readFactory; /** * Supported formats * - * @var \Magento\Developer\Model\XmlCatalog\Format\FormatInterface[] + * @var FormatInterface[] */ private $formats; /** - * @param \Magento\Framework\App\Utility\Files $filesUtility - * @param \Magento\Framework\Config\Dom\UrnResolver $urnResolver - * @param \Magento\Framework\Filesystem\Directory\ReadFactory $readFactory - * @param \Magento\Developer\Model\XmlCatalog\Format\FormatInterface[] $formats + * @param Files $filesUtility + * @param UrnResolver $urnResolver + * @param ReadFactory $readFactory + * @param FormatInterface[] $formats */ public function __construct( - \Magento\Framework\App\Utility\Files $filesUtility, - \Magento\Framework\Config\Dom\UrnResolver $urnResolver, - \Magento\Framework\Filesystem\Directory\ReadFactory $readFactory, + Files $filesUtility, + UrnResolver $urnResolver, + ReadFactory $readFactory, array $formats = [] ) { $this->filesUtility = $filesUtility; @@ -75,7 +80,7 @@ public function __construct( } /** - * {@inheritdoc} + * @inheritdoc */ protected function configure() { @@ -86,7 +91,7 @@ protected function configure() self::IDE_OPTION, null, InputOption::VALUE_REQUIRED, - 'Format in which catalog will be generated. Supported: ['. + 'Format in which catalog will be generated. Supported: [' . implode(', ', $this->getSupportedFormats()) . ']', 'phpstorm' ), @@ -111,19 +116,21 @@ private function getUrnDictionary(OutputInterface $output) $files = $this->filesUtility->getXmlCatalogFiles('*.xml'); $files = array_merge($files, $this->filesUtility->getXmlCatalogFiles('*.xsd')); - $urns = []; + $urns = [[]]; foreach ($files as $file) { + // phpcs:ignore Magento2.Functions.DiscouragedFunction $fileDir = dirname($file[0]); + // phpcs:ignore Magento2.Functions.DiscouragedFunction $fileName = basename($file[0]); $read = $this->readFactory->create($fileDir); $content = $read->readFile($fileName); $matches = []; preg_match_all('/schemaLocation="(urn\:magento\:[^"]*)"/i', $content, $matches); if (isset($matches[1])) { - $urns = array_merge($urns, $matches[1]); + $urns[] = $matches[1]; } } - $urns = array_unique($urns); + $urns = array_unique(array_merge(...$urns)); $paths = []; foreach ($urns as $urn) { try { @@ -139,27 +146,32 @@ private function getUrnDictionary(OutputInterface $output) } /** - * {@inheritdoc} + * @inheritdoc + * * @throws \InvalidArgumentException */ protected function execute(InputInterface $input, OutputInterface $output) { $ideName = $input->getOption(self::IDE_OPTION); - $ideFilePath = $input->getArgument(self::IDE_FILE_PATH_ARGUMENT); + $ideFilePath = $input->getArgument(self::IDE_FILE_PATH_ARGUMENT); $urnDictionary = $this->getUrnDictionary($output); - if ($formatter = $this->getFormatters($ideName)) { - $formatter->generateCatalog($urnDictionary, $ideFilePath); - } else { + + $formatter = $this->getFormatters($ideName); + if (!$formatter instanceof FormatInterface) { throw new InputException(__("Format for IDE '%1' is not supported", $ideName)); } + + $formatter->generateCatalog($urnDictionary, $ideFilePath); + + return Cli::RETURN_SUCCESS; } /** * Get formatter based on format * * @param string $format - * @return \Magento\Developer\Model\XmlCatalog\Format\FormatInterface|false + * @return FormatInterface|false */ private function getFormatters($format) { diff --git a/app/code/Magento/Directory/Model/AllowedCountries.php b/app/code/Magento/Directory/Model/AllowedCountries.php index b9f2d829dd1a6..2ceeb70ba5b01 100644 --- a/app/code/Magento/Directory/Model/AllowedCountries.php +++ b/app/code/Magento/Directory/Model/AllowedCountries.php @@ -62,13 +62,11 @@ public function getAllowedCountries( switch ($scope) { case ScopeInterface::SCOPE_WEBSITES: case ScopeInterface::SCOPE_STORES: - $allowedCountries = []; + $allowedCountries = [[]]; foreach ($scopeCode as $singleFilter) { - $allowedCountries = array_merge( - $allowedCountries, - $this->getCountriesFromConfig($this->getSingleScope($scope), $singleFilter) - ); + $allowedCountries[] = $this->getCountriesFromConfig($this->getSingleScope($scope), $singleFilter); } + $allowedCountries = array_merge(...$allowedCountries); break; default: $allowedCountries = $this->getCountriesFromConfig($scope, $scopeCode); diff --git a/app/code/Magento/Eav/Block/Adminhtml/Attribute/Edit/Options/Options.php b/app/code/Magento/Eav/Block/Adminhtml/Attribute/Edit/Options/Options.php index 7af7bf447c45a..69f417e1ea732 100644 --- a/app/code/Magento/Eav/Block/Adminhtml/Attribute/Edit/Options/Options.php +++ b/app/code/Magento/Eav/Block/Adminhtml/Attribute/Edit/Options/Options.php @@ -152,10 +152,10 @@ protected function _prepareOptionValues( $inputType = ''; } - $values = []; + $values = [[]]; $isSystemAttribute = is_array($optionCollection); if ($isSystemAttribute) { - $values = $this->getPreparedValues($optionCollection, $isSystemAttribute, $inputType, $defaultValues); + $values[] = $this->getPreparedValues($optionCollection, $isSystemAttribute, $inputType, $defaultValues); } else { $optionCollection->setPageSize(200); $pageCount = $optionCollection->getLastPageNumber(); @@ -163,15 +163,12 @@ protected function _prepareOptionValues( while ($currentPage <= $pageCount) { $optionCollection->clear(); $optionCollection->setCurPage($currentPage); - $values = array_merge( - $values, - $this->getPreparedValues($optionCollection, $isSystemAttribute, $inputType, $defaultValues) - ); + $values[] = $this->getPreparedValues($optionCollection, $isSystemAttribute, $inputType, $defaultValues); $currentPage++; } } - return $values; + return array_merge(...$values); } /** diff --git a/app/code/Magento/Eav/Model/Form.php b/app/code/Magento/Eav/Model/Form.php index a34b53eede354..074c6cf46a2f4 100644 --- a/app/code/Magento/Eav/Model/Form.php +++ b/app/code/Magento/Eav/Model/Form.php @@ -3,6 +3,7 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ + namespace Magento\Eav\Model; use Magento\Framework\App\RequestInterface; @@ -10,6 +11,7 @@ /** * EAV Entity Form Model * + * phpcs:disable Magento2.Classes.AbstractApi * @api * @SuppressWarnings(PHPMD.TooManyFields) * @SuppressWarnings(PHPMD.CouplingBetweenObjects) @@ -274,8 +276,8 @@ public function getStore() /** * Return current form code * - * @throws \Magento\Framework\Exception\LocalizedException * @return string + * @throws \Magento\Framework\Exception\LocalizedException */ public function getFormCode() { @@ -303,8 +305,8 @@ public function getEntityType() /** * Return current entity instance * - * @throws \Magento\Framework\Exception\LocalizedException * @return \Magento\Framework\Model\AbstractModel + * @throws \Magento\Framework\Exception\LocalizedException */ public function getEntity() { @@ -485,11 +487,11 @@ public function validateData(array $data) { $validator = $this->_getValidator($data); if (!$validator->isValid($this->getEntity())) { - $messages = []; + $messages = [[]]; foreach ($validator->getMessages() as $errorMessages) { - $messages = array_merge($messages, (array)$errorMessages); + $messages[] = (array)$errorMessages; } - return $messages; + return array_merge(...$messages); } return true; } diff --git a/app/code/Magento/Elasticsearch/Model/Adapter/FieldMapper/Product/CompositeFieldProvider.php b/app/code/Magento/Elasticsearch/Model/Adapter/FieldMapper/Product/CompositeFieldProvider.php index 8038c8c05bc1c..b276b67ff7fba 100644 --- a/app/code/Magento/Elasticsearch/Model/Adapter/FieldMapper/Product/CompositeFieldProvider.php +++ b/app/code/Magento/Elasticsearch/Model/Adapter/FieldMapper/Product/CompositeFieldProvider.php @@ -40,12 +40,12 @@ public function __construct(array $providers) */ public function getFields(array $context = []): array { - $allAttributes = []; + $allAttributes = [[]]; foreach ($this->providers as $provider) { - $allAttributes = array_merge($allAttributes, $provider->getFields($context)); + $allAttributes[] = $provider->getFields($context); } - return $allAttributes; + return array_merge(...$allAttributes); } } diff --git a/app/code/Magento/GroupedProduct/Block/Cart/Item/Renderer/Grouped.php b/app/code/Magento/GroupedProduct/Block/Cart/Item/Renderer/Grouped.php index e85d4eeca730a..197be38fb7f5f 100644 --- a/app/code/Magento/GroupedProduct/Block/Cart/Item/Renderer/Grouped.php +++ b/app/code/Magento/GroupedProduct/Block/Cart/Item/Renderer/Grouped.php @@ -45,10 +45,10 @@ public function getGroupedProduct() */ public function getIdentities() { - $identities = parent::getIdentities(); + $identities = [parent::getIdentities()]; if ($this->getItem()) { - $identities = array_merge($identities, $this->getGroupedProduct()->getIdentities()); + $identities[] = $this->getGroupedProduct()->getIdentities(); } - return $identities; + return array_merge(...$identities); } } diff --git a/app/code/Magento/GroupedProduct/Block/Stockqty/Type/Grouped.php b/app/code/Magento/GroupedProduct/Block/Stockqty/Type/Grouped.php index f666cf8d90af9..97dc90ec93493 100644 --- a/app/code/Magento/GroupedProduct/Block/Stockqty/Type/Grouped.php +++ b/app/code/Magento/GroupedProduct/Block/Stockqty/Type/Grouped.php @@ -32,10 +32,10 @@ protected function _getChildProducts() */ public function getIdentities() { - $identities = []; + $identities = [[]]; foreach ($this->getChildProducts() as $item) { - $identities = array_merge($identities, $item->getIdentities()); + $identities[] = $item->getIdentities(); } - return $identities; + return array_merge(...$identities); } } diff --git a/app/code/Magento/ImportExport/Model/Import/ErrorProcessing/ProcessingErrorAggregator.php b/app/code/Magento/ImportExport/Model/Import/ErrorProcessing/ProcessingErrorAggregator.php index 028bf2c464d4b..5ea6227231543 100644 --- a/app/code/Magento/ImportExport/Model/Import/ErrorProcessing/ProcessingErrorAggregator.php +++ b/app/code/Magento/ImportExport/Model/Import/ErrorProcessing/ProcessingErrorAggregator.php @@ -237,16 +237,12 @@ public function hasFatalExceptions() */ public function getAllErrors() { - $result = []; - if (empty($this->items)) { - return $result; - } - - foreach (array_values($this->items['rows']) as $errors) { - $result = array_merge($result, $errors); + if (empty($this->items) || empty($this->items['rows'])) { + return []; } - return $result; + $errors = array_values($this->items['rows']); + return array_merge(...$errors); } /** @@ -257,14 +253,14 @@ public function getAllErrors() */ public function getErrorsByCode(array $codes) { - $result = []; + $result = [[]]; foreach ($codes as $code) { if (isset($this->items['codes'][$code])) { - $result = array_merge($result, $this->items['codes'][$code]); + $result[] = $this->items['codes'][$code]; } } - return $result; + return array_merge(...$result); } /** diff --git a/app/code/Magento/Integration/Block/Adminhtml/Integration/Activate/Permissions/Tab/Webapi.php b/app/code/Magento/Integration/Block/Adminhtml/Integration/Activate/Permissions/Tab/Webapi.php index 3c719a5814615..2d323fea34e7d 100644 --- a/app/code/Magento/Integration/Block/Adminhtml/Integration/Activate/Permissions/Tab/Webapi.php +++ b/app/code/Magento/Integration/Block/Adminhtml/Integration/Activate/Permissions/Tab/Webapi.php @@ -105,7 +105,7 @@ protected function _construct() } /** - * {@inheritdoc} + * @inheritdoc */ public function canShowTab() { @@ -116,7 +116,7 @@ public function canShowTab() } /** - * {@inheritdoc} + * @inheritdoc * * @codeCoverageIgnore */ @@ -126,7 +126,7 @@ public function getTabLabel() } /** - * {@inheritdoc} + * @inheritdoc * * @codeCoverageIgnore */ @@ -136,7 +136,7 @@ public function getTabTitle() } /** - * {@inheritdoc} + * @inheritdoc * * @codeCoverageIgnore */ @@ -222,13 +222,13 @@ public function isTreeEmpty() */ protected function _getAllResourceIds(array $resources) { - $resourceIds = []; + $resourceIds = [[]]; foreach ($resources as $resource) { - $resourceIds[] = $resource['id']; + $resourceIds[] = [$resource['id']]; if (isset($resource['children'])) { - $resourceIds = array_merge($resourceIds, $this->_getAllResourceIds($resource['children'])); + $resourceIds[] = $this->_getAllResourceIds($resource['children']); } } - return $resourceIds; + return array_merge(...$resourceIds); } } diff --git a/app/code/Magento/Multishipping/Test/Unit/Plugin/DisableMultishippingModeTest.php b/app/code/Magento/Multishipping/Test/Unit/Plugin/DisableMultishippingModeTest.php index 02ae1a70ce801..829d5a9ce2763 100644 --- a/app/code/Magento/Multishipping/Test/Unit/Plugin/DisableMultishippingModeTest.php +++ b/app/code/Magento/Multishipping/Test/Unit/Plugin/DisableMultishippingModeTest.php @@ -16,7 +16,7 @@ use Magento\Quote\Model\Quote; /** - * Class DisableMultishippingModeTest + * Set of Unit Tets to cover DisableMultishippingMode */ class DisableMultishippingModeTest extends \PHPUnit\Framework\TestCase { @@ -59,10 +59,10 @@ protected function setUp() public function testExecuteTurnsOffMultishippingModeOnMultishippingQuote(): void { $subject = $this->createMock(Index::class); - $extensionAttributes = $this->createPartialMock( - CartExtensionInterface::class, - ['setShippingAssignments', 'getShippingAssignments'] - ); + $extensionAttributes = $this->getMockBuilder(CartExtensionInterface::class) + ->disableOriginalConstructor() + ->setMethods(['setShippingAssignments', 'getShippingAssignments']) + ->getMockForAbstractClass(); $extensionAttributes->method('getShippingAssignments') ->willReturn( $this->createMock(ShippingAssignmentInterface::class) diff --git a/app/code/Magento/PageCache/Model/Layout/LayoutPlugin.php b/app/code/Magento/PageCache/Model/Layout/LayoutPlugin.php index 88619673ad425..b4d9cb2d5e076 100644 --- a/app/code/Magento/PageCache/Model/Layout/LayoutPlugin.php +++ b/app/code/Magento/PageCache/Model/Layout/LayoutPlugin.php @@ -3,8 +3,15 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ + namespace Magento\PageCache\Model\Layout; +use Magento\Framework\App\MaintenanceMode; +use Magento\Framework\App\ResponseInterface; +use Magento\Framework\DataObject\IdentityInterface; +use Magento\Framework\View\Layout; +use Magento\PageCache\Model\Config; + /** * Class LayoutPlugin * @@ -13,31 +20,31 @@ class LayoutPlugin { /** - * @var \Magento\PageCache\Model\Config + * @var Config */ protected $config; /** - * @var \Magento\Framework\App\ResponseInterface + * @var ResponseInterface */ protected $response; /** - * @var \Magento\Framework\App\MaintenanceMode + * @var MaintenanceMode */ private $maintenanceMode; /** * Constructor * - * @param \Magento\Framework\App\ResponseInterface $response - * @param \Magento\PageCache\Model\Config $config - * @param \Magento\Framework\App\MaintenanceMode $maintenanceMode + * @param ResponseInterface $response + * @param Config $config + * @param MaintenanceMode $maintenanceMode */ public function __construct( - \Magento\Framework\App\ResponseInterface $response, - \Magento\PageCache\Model\Config $config, - \Magento\Framework\App\MaintenanceMode $maintenanceMode + ResponseInterface $response, + Config $config, + MaintenanceMode $maintenanceMode ) { $this->response = $response; $this->config = $config; @@ -49,11 +56,11 @@ public function __construct( * * We have to set public headers in order to tell Varnish and Builtin app that page should be cached * - * @param \Magento\Framework\View\Layout $subject + * @param Layout $subject * @param mixed $result * @return mixed */ - public function afterGenerateXml(\Magento\Framework\View\Layout $subject, $result) + public function afterGenerateXml(Layout $subject, $result) { if ($subject->isCacheable() && !$this->maintenanceMode->isOn() && $this->config->isEnabled()) { $this->response->setPublicHeaders($this->config->getTtl()); @@ -64,26 +71,25 @@ public function afterGenerateXml(\Magento\Framework\View\Layout $subject, $resul /** * Retrieve all identities from blocks for further cache invalidation * - * @param \Magento\Framework\View\Layout $subject + * @param Layout $subject * @param mixed $result * @return mixed */ - public function afterGetOutput(\Magento\Framework\View\Layout $subject, $result) + public function afterGetOutput(Layout $subject, $result) { if ($subject->isCacheable() && $this->config->isEnabled()) { - $tags = []; + $tags = [[]]; foreach ($subject->getAllBlocks() as $block) { - if ($block instanceof \Magento\Framework\DataObject\IdentityInterface) { + if ($block instanceof IdentityInterface) { $isEsiBlock = $block->getTtl() > 0; - $isVarnish = $this->config->getType() == \Magento\PageCache\Model\Config::VARNISH; + $isVarnish = $this->config->getType() == Config::VARNISH; if ($isVarnish && $isEsiBlock) { continue; } - // phpcs:ignore - $tags = array_merge($tags, $block->getIdentities()); + $tags[] = $block->getIdentities(); } } - $tags = array_unique($tags); + $tags = array_unique(array_merge(...$tags)); $this->response->setHeader('X-Magento-Tags', implode(',', $tags)); } return $result; diff --git a/app/code/Magento/Payment/Gateway/Validator/ValidatorComposite.php b/app/code/Magento/Payment/Gateway/Validator/ValidatorComposite.php index 8ea97d31ed4d9..f96c08a9605a8 100644 --- a/app/code/Magento/Payment/Gateway/Validator/ValidatorComposite.php +++ b/app/code/Magento/Payment/Gateway/Validator/ValidatorComposite.php @@ -3,6 +3,7 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ + namespace Magento\Payment\Gateway\Validator; use Magento\Framework\ObjectManager\TMap; @@ -57,26 +58,25 @@ public function __construct( public function validate(array $validationSubject) { $isValid = true; - $failsDescriptionAggregate = []; - $errorCodesAggregate = []; + $failsDescriptionAggregate = [[]]; + $errorCodesAggregate = [[]]; foreach ($this->validators as $key => $validator) { $result = $validator->validate($validationSubject); if (!$result->isValid()) { $isValid = false; - $failsDescriptionAggregate = array_merge( - $failsDescriptionAggregate, - $result->getFailsDescription() - ); - $errorCodesAggregate = array_merge( - $errorCodesAggregate, - $result->getErrorCodes() - ); + $failsDescriptionAggregate[] = $result->getFailsDescription(); + $errorCodesAggregate[] = $result->getErrorCodes(); + if (!empty($this->chainBreakingValidators[$key])) { break; } } } - return $this->createResult($isValid, $failsDescriptionAggregate, $errorCodesAggregate); + return $this->createResult( + $isValid, + array_merge(...$failsDescriptionAggregate), + array_merge(...$errorCodesAggregate) + ); } } diff --git a/app/code/Magento/Paypal/Model/Config/Structure/PaymentSectionModifier.php b/app/code/Magento/Paypal/Model/Config/Structure/PaymentSectionModifier.php index f1c414e6faa9b..61410499e956e 100644 --- a/app/code/Magento/Paypal/Model/Config/Structure/PaymentSectionModifier.php +++ b/app/code/Magento/Paypal/Model/Config/Structure/PaymentSectionModifier.php @@ -3,6 +3,7 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ + namespace Magento\Paypal\Model\Config\Structure; /** @@ -60,9 +61,9 @@ public function modify(array $initialStructure) unset($childData['children'][$moveInstruction['section']]); unset($moveInstruction['data']['displayIn']); $changedStructure - [$moveInstruction['parent']] - ['children'] - [$moveInstruction['section']] = $moveInstruction['data']; + [$moveInstruction['parent']] + ['children'] + [$moveInstruction['section']] = $moveInstruction['data']; } } if (!isset($moveInstructions[$childSection])) { @@ -83,7 +84,7 @@ public function modify(array $initialStructure) */ private function getMoveInstructions($section, $data) { - $moved = []; + $moved = [[]]; if (array_key_exists('children', $data)) { foreach ($data['children'] as $childSection => $childData) { @@ -91,23 +92,20 @@ private function getMoveInstructions($section, $data) if (isset($movedChildren[$childSection])) { unset($data['children'][$childSection]); } - $moved = array_merge($moved, $movedChildren); + $moved[] = $movedChildren; } } if (isset($data['displayIn']) && in_array($data['displayIn'], self::$specialGroups)) { - $moved = array_merge( - [ - $section => [ + $moved[] = [ + $section => [ 'parent' => $data['displayIn'], 'section' => $section, 'data' => $data - ] - ], - $moved - ); + ] + ]; } - return $moved; + return array_merge(...$moved); } } diff --git a/app/code/Magento/QuoteGraphQl/Model/Cart/BuyRequest/BuyRequestBuilder.php b/app/code/Magento/QuoteGraphQl/Model/Cart/BuyRequest/BuyRequestBuilder.php index 90f32e96a5fde..c14cc1324732c 100644 --- a/app/code/Magento/QuoteGraphQl/Model/Cart/BuyRequest/BuyRequestBuilder.php +++ b/app/code/Magento/QuoteGraphQl/Model/Cart/BuyRequest/BuyRequestBuilder.php @@ -45,11 +45,11 @@ public function __construct( */ public function build(array $cartItemData): DataObject { - $requestData = []; + $requestData = [[]]; foreach ($this->providers as $provider) { - $requestData = array_merge($requestData, $provider->execute($cartItemData)); + $requestData[] = $provider->execute($cartItemData); } - return $this->dataObjectFactory->create(['data' => $requestData]); + return $this->dataObjectFactory->create(['data' => array_merge(...$requestData)]); } } diff --git a/app/code/Magento/Reports/Block/Product/Viewed.php b/app/code/Magento/Reports/Block/Product/Viewed.php index 5f9fdf8533523..ba4d03182213a 100644 --- a/app/code/Magento/Reports/Block/Product/Viewed.php +++ b/app/code/Magento/Reports/Block/Product/Viewed.php @@ -59,8 +59,7 @@ public function getCount() } /** - * Prepare to html - * check has viewed products + * Prepare to html check has viewed products * * @return string */ @@ -77,10 +76,10 @@ protected function _toHtml() */ public function getIdentities() { - $identities = []; + $identities = [[]]; foreach ($this->getItemsCollection() as $item) { - $identities = array_merge($identities, $item->getIdentities()); + $identities[] = $item->getIdentities(); } - return $identities; + return array_merge(...$identities); } } diff --git a/app/code/Magento/Sales/Block/Adminhtml/Items/Column/DefaultColumn.php b/app/code/Magento/Sales/Block/Adminhtml/Items/Column/DefaultColumn.php index 80dcce2fd1be4..efef617acf900 100644 --- a/app/code/Magento/Sales/Block/Adminhtml/Items/Column/DefaultColumn.php +++ b/app/code/Magento/Sales/Block/Adminhtml/Items/Column/DefaultColumn.php @@ -68,19 +68,19 @@ public function getItem() */ public function getOrderOptions() { - $result = []; + $result = [[]]; if ($options = $this->getItem()->getProductOptions()) { if (isset($options['options'])) { - $result = array_merge($result, $options['options']); + $result[] = $options['options']; } if (isset($options['additional_options'])) { - $result = array_merge($result, $options['additional_options']); + $result[] = $options['additional_options']; } if (!empty($options['attributes_info'])) { - $result = array_merge($options['attributes_info'], $result); + $result[] = $options['attributes_info']; } } - return $result; + return array_merge(...$result); } /** diff --git a/app/code/Magento/Sales/Block/Order/Email/Items/DefaultItems.php b/app/code/Magento/Sales/Block/Order/Email/Items/DefaultItems.php index 0aa4f807700b6..064405daf89a8 100644 --- a/app/code/Magento/Sales/Block/Order/Email/Items/DefaultItems.php +++ b/app/code/Magento/Sales/Block/Order/Email/Items/DefaultItems.php @@ -29,27 +29,31 @@ public function getOrder() } /** + * Returns Items options as array + * * @return array */ public function getItemOptions() { - $result = []; + $result = [[]]; if ($options = $this->getItem()->getOrderItem()->getProductOptions()) { if (isset($options['options'])) { - $result = array_merge($result, $options['options']); + $result[] = $options['options']; } if (isset($options['additional_options'])) { - $result = array_merge($result, $options['additional_options']); + $result[] = $options['additional_options']; } if (isset($options['attributes_info'])) { - $result = array_merge($result, $options['attributes_info']); + $result[] = $options['attributes_info']; } } - return $result; + return array_merge(...$result); } /** + * Formats the value in HTML + * * @param string|array $value * @return string */ @@ -70,7 +74,9 @@ public function getValueHtml($value) } /** - * @param mixed $item + * Returns Product SKU for Item provided + * + * @param OrderItem $item * @return mixed */ public function getSku($item) diff --git a/app/code/Magento/Sales/Block/Order/Email/Items/Order/DefaultOrder.php b/app/code/Magento/Sales/Block/Order/Email/Items/Order/DefaultOrder.php index ae2dec6aefa6e..0291a1275c350 100644 --- a/app/code/Magento/Sales/Block/Order/Email/Items/Order/DefaultOrder.php +++ b/app/code/Magento/Sales/Block/Order/Email/Items/Order/DefaultOrder.php @@ -3,6 +3,7 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ + namespace Magento\Sales\Block\Order\Email\Items\Order; use Magento\Sales\Model\Order\Item as OrderItem; @@ -27,48 +28,49 @@ public function getOrder() } /** + * Returns array of Item options + * * @return array */ public function getItemOptions() { - $result = []; + $result = [[]]; if ($options = $this->getItem()->getProductOptions()) { if (isset($options['options'])) { - $result = array_merge($result, $options['options']); + $result[] = $options['options']; } if (isset($options['additional_options'])) { - $result = array_merge($result, $options['additional_options']); + $result[] = $options['additional_options']; } if (isset($options['attributes_info'])) { - $result = array_merge($result, $options['attributes_info']); + $result[] = $options['attributes_info']; } } - return $result; + return array_merge(...$result); } /** + * Formats the value in HTML + * * @param string|array $value * @return string */ public function getValueHtml($value) { if (is_array($value)) { - return sprintf( - '%d', - $value['qty'] - ) . ' x ' . $this->escapeHtml( - $value['title'] - ) . " " . $this->getItem()->getOrder()->formatPrice( - $value['price'] - ); + return sprintf('%d', $value['qty']) + . ' x ' . $this->escapeHtml($value['title']) + . " " . $this->getItem()->getOrder()->formatPrice($value['price']); } else { return $this->escapeHtml($value); } } /** - * @param mixed $item + * Returns Product SKU for Item provided + * + * @param OrderItem $item * @return mixed */ public function getSku($item) diff --git a/app/code/Magento/Sales/Block/Order/Item/Renderer/DefaultRenderer.php b/app/code/Magento/Sales/Block/Order/Item/Renderer/DefaultRenderer.php index 2e119d0bf887a..bca6d49760d9a 100644 --- a/app/code/Magento/Sales/Block/Order/Item/Renderer/DefaultRenderer.php +++ b/app/code/Magento/Sales/Block/Order/Item/Renderer/DefaultRenderer.php @@ -6,7 +6,12 @@ namespace Magento\Sales\Block\Order\Item\Renderer; -use Magento\Sales\Model\Order\CreditMemo\Item as CreditMemoItem; +use Magento\Catalog\Model\Product\OptionFactory; +use Magento\Framework\DataObject; +use Magento\Framework\Stdlib\StringUtils; +use Magento\Framework\View\Element\AbstractBlock; +use Magento\Framework\View\Element\Template\Context; +use Magento\Sales\Model\Order\Creditmemo\Item as CreditMemoItem; use Magento\Sales\Model\Order\Invoice\Item as InvoiceItem; use Magento\Sales\Model\Order\Item as OrderItem; @@ -21,25 +26,25 @@ class DefaultRenderer extends \Magento\Framework\View\Element\Template /** * Magento string lib * - * @var \Magento\Framework\Stdlib\StringUtils + * @var StringUtils */ protected $string; /** - * @var \Magento\Catalog\Model\Product\OptionFactory + * @var OptionFactory */ protected $_productOptionFactory; /** - * @param \Magento\Framework\View\Element\Template\Context $context - * @param \Magento\Framework\Stdlib\StringUtils $string - * @param \Magento\Catalog\Model\Product\OptionFactory $productOptionFactory + * @param Context $context + * @param StringUtils $string + * @param OptionFactory $productOptionFactory * @param array $data */ public function __construct( - \Magento\Framework\View\Element\Template\Context $context, - \Magento\Framework\Stdlib\StringUtils $string, - \Magento\Catalog\Model\Product\OptionFactory $productOptionFactory, + Context $context, + StringUtils $string, + OptionFactory $productOptionFactory, array $data = [] ) { $this->string = $string; @@ -50,10 +55,10 @@ public function __construct( /** * Set item. * - * @param \Magento\Framework\DataObject $item + * @param DataObject $item * @return $this */ - public function setItem(\Magento\Framework\DataObject $item) + public function setItem(DataObject $item) { $this->setData('item', $item); return $this; @@ -86,7 +91,7 @@ public function getOrder() */ public function getOrderItem() { - if ($this->getItem() instanceof \Magento\Sales\Model\Order\Item) { + if ($this->getItem() instanceof OrderItem) { return $this->getItem(); } else { return $this->getItem()->getOrderItem(); @@ -100,20 +105,20 @@ public function getOrderItem() */ public function getItemOptions() { - $result = []; + $result = [[]]; $options = $this->getOrderItem()->getProductOptions(); if ($options) { if (isset($options['options'])) { - $result = array_merge($result, $options['options']); + $result[] = $options['options']; } if (isset($options['additional_options'])) { - $result = array_merge($result, $options['additional_options']); + $result[] = $options['additional_options']; } if (isset($options['attributes_info'])) { - $result = array_merge($result, $options['attributes_info']); + $result[] = $options['attributes_info']; } } - return $result; + return array_merge(...$result); } /** diff --git a/app/code/Magento/Sales/Model/Order/Pdf/Items/AbstractItems.php b/app/code/Magento/Sales/Model/Order/Pdf/Items/AbstractItems.php index 422ff1746c9a6..29e011217ef20 100644 --- a/app/code/Magento/Sales/Model/Order/Pdf/Items/AbstractItems.php +++ b/app/code/Magento/Sales/Model/Order/Pdf/Items/AbstractItems.php @@ -6,41 +6,54 @@ namespace Magento\Sales\Model\Order\Pdf\Items; use Magento\Framework\App\Filesystem\DirectoryList; +use Magento\Framework\Data\Collection\AbstractDb; +use Magento\Framework\DataObject; +use Magento\Framework\Filesystem; +use Magento\Framework\Filesystem\Directory\ReadInterface; +use Magento\Framework\Filter\FilterManager; +use Magento\Framework\Model\AbstractModel; +use Magento\Framework\Model\Context; +use Magento\Framework\Model\ResourceModel\AbstractResource; +use Magento\Framework\Registry; +use Magento\Sales\Model\Order; +use Magento\Sales\Model\Order\Pdf\AbstractPdf; +use Magento\Tax\Helper\Data as TaxHelper; /** * Sales Order Pdf Items renderer Abstract * + * phpcs:disable Magento2.Classes.AbstractApi * @api * @SuppressWarnings(PHPMD.CouplingBetweenObjects) * @since 100.0.2 */ -abstract class AbstractItems extends \Magento\Framework\Model\AbstractModel +abstract class AbstractItems extends AbstractModel { /** * Order model * - * @var \Magento\Sales\Model\Order + * @var Order */ protected $_order; /** * Source model (invoice, shipment, creditmemo) * - * @var \Magento\Framework\Model\AbstractModel + * @var AbstractModel */ protected $_source; /** * Item object * - * @var \Magento\Framework\DataObject + * @var DataObject */ protected $_item; /** * Pdf object * - * @var \Magento\Sales\Model\Order\Pdf\AbstractPdf + * @var AbstractPdf */ protected $_pdf; @@ -54,38 +67,38 @@ abstract class AbstractItems extends \Magento\Framework\Model\AbstractModel /** * Tax data * - * @var \Magento\Tax\Helper\Data + * @var TaxHelper */ protected $_taxData; /** - * @var \Magento\Framework\Filesystem\Directory\ReadInterface + * @var ReadInterface */ protected $_rootDirectory; /** - * @var \Magento\Framework\Filter\FilterManager + * @var FilterManager */ protected $filterManager; /** - * @param \Magento\Framework\Model\Context $context - * @param \Magento\Framework\Registry $registry - * @param \Magento\Tax\Helper\Data $taxData - * @param \Magento\Framework\Filesystem $filesystem , - * @param \Magento\Framework\Filter\FilterManager $filterManager - * @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource - * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection + * @param Context $context + * @param Registry $registry + * @param TaxHelper $taxData + * @param Filesystem $filesystem , + * @param FilterManager $filterManager + * @param AbstractResource $resource + * @param AbstractDb $resourceCollection * @param array $data */ public function __construct( - \Magento\Framework\Model\Context $context, - \Magento\Framework\Registry $registry, - \Magento\Tax\Helper\Data $taxData, - \Magento\Framework\Filesystem $filesystem, - \Magento\Framework\Filter\FilterManager $filterManager, - \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, - \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, + Context $context, + Registry $registry, + TaxHelper $taxData, + Filesystem $filesystem, + FilterManager $filterManager, + AbstractResource $resource = null, + AbstractDb $resourceCollection = null, array $data = [] ) { $this->filterManager = $filterManager; @@ -97,10 +110,10 @@ public function __construct( /** * Set order model * - * @param \Magento\Sales\Model\Order $order + * @param Order $order * @return $this */ - public function setOrder(\Magento\Sales\Model\Order $order) + public function setOrder(Order $order) { $this->_order = $order; return $this; @@ -109,10 +122,10 @@ public function setOrder(\Magento\Sales\Model\Order $order) /** * Set Source model * - * @param \Magento\Framework\Model\AbstractModel $source + * @param AbstractModel $source * @return $this */ - public function setSource(\Magento\Framework\Model\AbstractModel $source) + public function setSource(AbstractModel $source) { $this->_source = $source; return $this; @@ -121,10 +134,10 @@ public function setSource(\Magento\Framework\Model\AbstractModel $source) /** * Set item object * - * @param \Magento\Framework\DataObject $item + * @param DataObject $item * @return $this */ - public function setItem(\Magento\Framework\DataObject $item) + public function setItem(DataObject $item) { $this->_item = $item; return $this; @@ -133,10 +146,10 @@ public function setItem(\Magento\Framework\DataObject $item) /** * Set Pdf model * - * @param \Magento\Sales\Model\Order\Pdf\AbstractPdf $pdf + * @param AbstractPdf $pdf * @return $this */ - public function setPdf(\Magento\Sales\Model\Order\Pdf\AbstractPdf $pdf) + public function setPdf(AbstractPdf $pdf) { $this->_pdf = $pdf; return $this; @@ -313,20 +326,20 @@ public function getItemPricesForDisplay() */ public function getItemOptions() { - $result = []; + $result = [[]]; $options = $this->getItem()->getOrderItem()->getProductOptions(); if ($options) { if (isset($options['options'])) { - $result = array_merge($result, $options['options']); + $result[] = $options['options']; } if (isset($options['additional_options'])) { - $result = array_merge($result, $options['additional_options']); + $result[] = $options['additional_options']; } if (isset($options['attributes_info'])) { - $result = array_merge($result, $options['attributes_info']); + $result[] = $options['attributes_info']; } } - return $result; + return array_merge(...$result); } /** diff --git a/app/code/Magento/Sales/Model/ResourceModel/Provider/NotSyncedDataProvider.php b/app/code/Magento/Sales/Model/ResourceModel/Provider/NotSyncedDataProvider.php index aa2ac20f8f55c..645e411b80b67 100644 --- a/app/code/Magento/Sales/Model/ResourceModel/Provider/NotSyncedDataProvider.php +++ b/app/code/Magento/Sales/Model/ResourceModel/Provider/NotSyncedDataProvider.php @@ -3,6 +3,7 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ + namespace Magento\Sales\Model\ResourceModel\Provider; use Magento\Framework\ObjectManager\TMapFactory; @@ -21,10 +22,8 @@ class NotSyncedDataProvider implements NotSyncedDataProviderInterface * @param TMapFactory $tmapFactory * @param array $providers */ - public function __construct( - TMapFactory $tmapFactory, - array $providers = [] - ) { + public function __construct(TMapFactory $tmapFactory, array $providers = []) + { $this->providers = $tmapFactory->create( [ 'array' => $providers, @@ -38,11 +37,11 @@ public function __construct( */ public function getIds($mainTableName, $gridTableName) { - $result = []; + $result = [[]]; foreach ($this->providers as $provider) { - $result = array_merge($result, $provider->getIds($mainTableName, $gridTableName)); + $result[] = $provider->getIds($mainTableName, $gridTableName); } - return array_unique($result); + return array_unique(array_merge(...$result)); } } diff --git a/app/code/Magento/Search/Model/Autocomplete.php b/app/code/Magento/Search/Model/Autocomplete.php index b50cd330d5d95..45957e8795744 100644 --- a/app/code/Magento/Search/Model/Autocomplete.php +++ b/app/code/Magento/Search/Model/Autocomplete.php @@ -5,6 +5,9 @@ */ namespace Magento\Search\Model; +/** + * Provides list of Autocomplete items + */ class Autocomplete implements AutocompleteInterface { /** @@ -23,15 +26,15 @@ public function __construct( } /** - * {@inheritdoc} + * @inheritdoc */ public function getItems() { - $data = []; + $data = [[]]; foreach ($this->dataProviders as $dataProvider) { - $data = array_merge($data, $dataProvider->getItems()); + $data[] = $dataProvider->getItems(); } - return $data; + return array_merge(...$data); } } diff --git a/app/code/Magento/Search/Model/SynonymGroupRepository.php b/app/code/Magento/Search/Model/SynonymGroupRepository.php index 75d7049afd949..dbc2b66b1f047 100644 --- a/app/code/Magento/Search/Model/SynonymGroupRepository.php +++ b/app/code/Magento/Search/Model/SynonymGroupRepository.php @@ -7,6 +7,7 @@ namespace Magento\Search\Model; use Magento\Framework\Exception\CouldNotDeleteException; +use Magento\Framework\Phrase; use Magento\Search\Api\Data\SynonymGroupInterface; use Magento\Search\Api\SynonymGroupRepositoryInterface; use Magento\Search\Model\ResourceModel\SynonymGroup as SynonymGroupResourceModel; @@ -37,7 +38,7 @@ class SynonymGroupRepository implements SynonymGroupRepositoryInterface * @param SynonymGroupResourceModel $resourceModel */ public function __construct( - \Magento\Search\Model\SynonymGroupFactory $synonymGroupFactory, + SynonymGroupFactory $synonymGroupFactory, SynonymGroupResourceModel $resourceModel ) { $this->synonymGroupFactory = $synonymGroupFactory; @@ -64,8 +65,8 @@ public function save(SynonymGroupInterface $synonymGroup, $errorOnMergeConflict * Deletes a synonym group * * @param SynonymGroupInterface $synonymGroup - * @throws CouldNotDeleteException * @return bool + * @throws CouldNotDeleteException */ public function delete(SynonymGroupInterface $synonymGroup) { @@ -149,17 +150,17 @@ private function create(SynonymGroupInterface $synonymGroup, $errorOnMergeConfli */ private function merge(SynonymGroupInterface $synonymGroupToMerge, array $matchingGroupIds) { - $mergedSynonyms = []; + $mergedSynonyms = [[]]; foreach ($matchingGroupIds as $groupId) { /** @var SynonymGroup $synonymGroupModel */ $synonymGroupModel = $this->synonymGroupFactory->create(); $synonymGroupModel->load($groupId); - $mergedSynonyms = array_merge($mergedSynonyms, explode(',', $synonymGroupModel->getSynonymGroup())); + $mergedSynonyms[] = explode(',', $synonymGroupModel->getSynonymGroup()); $synonymGroupModel->delete(); } - $mergedSynonyms = array_merge($mergedSynonyms, explode(',', $synonymGroupToMerge->getSynonymGroup())); - $mergedSynonyms = array_unique($mergedSynonyms); - return $mergedSynonyms; + $mergedSynonyms[] = explode(',', $synonymGroupToMerge->getSynonymGroup()); + + return array_unique(array_merge(...$mergedSynonyms)); } /** @@ -222,7 +223,7 @@ private function update( * Gets merge conflict exception message * * @param string[] $matchingSynonymGroups - * @return \Magento\Framework\Phrase + * @return Phrase */ private function getExceptionMessage($matchingSynonymGroups) { diff --git a/app/code/Magento/Tax/Model/ResourceModel/Calculation/Rate/Collection.php b/app/code/Magento/Tax/Model/ResourceModel/Calculation/Rate/Collection.php index 9b344f6e96f65..7863b70f6626a 100644 --- a/app/code/Magento/Tax/Model/ResourceModel/Calculation/Rate/Collection.php +++ b/app/code/Magento/Tax/Model/ResourceModel/Calculation/Rate/Collection.php @@ -7,9 +7,25 @@ /** * Tax rate collection */ + namespace Magento\Tax\Model\ResourceModel\Calculation\Rate; -class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection +use Magento\Framework\Data\Collection\Db\FetchStrategyInterface; +use Magento\Framework\Data\Collection\EntityFactory; +use Magento\Framework\DB\Adapter\AdapterInterface; +use Magento\Framework\Event\ManagerInterface; +use Magento\Framework\Model\ResourceModel\Db\AbstractDb; +use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection; +use Magento\Store\Model\Store; +use Magento\Store\Model\StoreManagerInterface; +use Magento\Tax\Model\Calculation\Rate; +use Magento\Tax\Model\ResourceModel\Calculation\Rate as RateResourceModel; +use Psr\Log\LoggerInterface; + +/** + * Collection of Calculation Rates + */ +class Collection extends AbstractCollection { /** * Value of fetched from DB of rules per cycle @@ -17,27 +33,27 @@ class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\Ab const TAX_RULES_CHUNK_SIZE = 1000; /** - * @var \Magento\Store\Model\StoreManagerInterface + * @var StoreManagerInterface */ protected $_storeManager; /** - * @param \Magento\Framework\Data\Collection\EntityFactory $entityFactory - * @param \Psr\Log\LoggerInterface $logger - * @param \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy - * @param \Magento\Framework\Event\ManagerInterface $eventManager - * @param \Magento\Store\Model\StoreManagerInterface $storeManager + * @param EntityFactory $entityFactory + * @param LoggerInterface $logger + * @param FetchStrategyInterface $fetchStrategy + * @param ManagerInterface $eventManager + * @param StoreManagerInterface $storeManager * @param mixed $connection - * @param \Magento\Framework\Model\ResourceModel\Db\AbstractDb $resource + * @param AbstractDb $resource */ public function __construct( - \Magento\Framework\Data\Collection\EntityFactory $entityFactory, - \Psr\Log\LoggerInterface $logger, - \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy, - \Magento\Framework\Event\ManagerInterface $eventManager, - \Magento\Store\Model\StoreManagerInterface $storeManager, - \Magento\Framework\DB\Adapter\AdapterInterface $connection = null, - \Magento\Framework\Model\ResourceModel\Db\AbstractDb $resource = null + EntityFactory $entityFactory, + LoggerInterface $logger, + FetchStrategyInterface $fetchStrategy, + ManagerInterface $eventManager, + StoreManagerInterface $storeManager, + AdapterInterface $connection = null, + AbstractDb $resource = null ) { $this->_storeManager = $storeManager; parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, $connection, $resource); @@ -50,10 +66,7 @@ public function __construct( */ protected function _construct() { - $this->_init( - \Magento\Tax\Model\Calculation\Rate::class, - \Magento\Tax\Model\ResourceModel\Calculation\Rate::class - ); + $this->_init(Rate::class, RateResourceModel::class); } /** @@ -90,7 +103,7 @@ public function joinRegionTable() /** * Join rate title for specified store * - * @param \Magento\Store\Model\Store|string|int $store + * @param Store|string|int $store * @return $this */ public function joinTitle($store = null) @@ -170,12 +183,10 @@ public function toOptionHash() } /** - * Convert items array to hash for select options - * using fetchItem method - * - * @see fetchItem() + * Convert items array to hash for select options using fetchItem method * * @return array + * @see fetchItem() */ public function toOptionHashOptimized() { @@ -195,7 +206,7 @@ public function getOptionRates() { $size = self::TAX_RULES_CHUNK_SIZE; $page = 1; - $rates = []; + $rates = [[]]; do { $offset = $size * ($page - 1); $this->getSelect()->reset(); @@ -206,11 +217,11 @@ public function getOptionRates() ) ->limit($size, $offset); - $rates = array_merge($rates, $this->toOptionArray()); + $rates[] = $this->toOptionArray(); $this->clear(); $page++; } while ($this->getSize() > $offset); - return $rates; + return array_merge(...$rates); } } diff --git a/app/code/Magento/Weee/Model/Total/Quote/Weee.php b/app/code/Magento/Weee/Model/Total/Quote/Weee.php index 96a40c9533f8f..449c6cd688668 100644 --- a/app/code/Magento/Weee/Model/Total/Quote/Weee.php +++ b/app/code/Magento/Weee/Model/Total/Quote/Weee.php @@ -7,10 +7,19 @@ namespace Magento\Weee\Model\Total\Quote; use Magento\Framework\Pricing\PriceCurrencyInterface; +use Magento\Quote\Api\Data\ShippingAssignmentInterface; +use Magento\Quote\Model\Quote; +use Magento\Quote\Model\Quote\Address; +use Magento\Quote\Model\Quote\Address\Total; use Magento\Quote\Model\Quote\Address\Total\AbstractTotal; +use Magento\Quote\Model\Quote\Item\AbstractItem; use Magento\Store\Model\Store; use Magento\Tax\Model\Sales\Total\Quote\CommonTaxCollector; +use Magento\Weee\Helper\Data as WeeHelper; +/** + * Calculate totals for Quote + */ class Weee extends AbstractTotal { /** @@ -23,7 +32,7 @@ class Weee extends AbstractTotal const ITEM_TYPE = 'weee'; /** - * @var \Magento\Weee\Helper\Data + * @var WeeHelper */ protected $weeeData; @@ -66,11 +75,11 @@ class Weee extends AbstractTotal protected $priceCurrency; /** - * @param \Magento\Weee\Helper\Data $weeeData + * @param WeeHelper $weeeData * @param PriceCurrencyInterface $priceCurrency */ public function __construct( - \Magento\Weee\Helper\Data $weeeData, + WeeHelper $weeeData, PriceCurrencyInterface $priceCurrency ) { $this->priceCurrency = $priceCurrency; @@ -82,15 +91,15 @@ public function __construct( /** * Collect Weee amounts for the quote / order * - * @param \Magento\Quote\Model\Quote $quote - * @param \Magento\Quote\Api\Data\ShippingAssignmentInterface $shippingAssignment - * @param \Magento\Quote\Model\Quote\Address\Total $total + * @param Quote $quote + * @param ShippingAssignmentInterface $shippingAssignment + * @param Total $total * @return $this */ public function collect( - \Magento\Quote\Model\Quote $quote, - \Magento\Quote\Api\Data\ShippingAssignmentInterface $shippingAssignment, - \Magento\Quote\Model\Quote\Address\Total $total + Quote $quote, + ShippingAssignmentInterface $shippingAssignment, + Total $total ) { AbstractTotal::collect($quote, $shippingAssignment, $total); $this->_store = $quote->getStore(); @@ -130,16 +139,16 @@ public function collect( /** * Calculate item fixed tax and prepare information for discount and regular taxation * - * @param \Magento\Quote\Model\Quote\Address $address - * @param \Magento\Quote\Model\Quote\Address\Total $total - * @param \Magento\Quote\Model\Quote\Item\AbstractItem $item - * @return void|$this + * @param Address $address + * @param Total $total + * @param AbstractItem $item + * @return void|$this * @SuppressWarnings(PHPMD.ExcessiveMethodLength) * @SuppressWarnings(PHPMD.UnusedLocalVariable) */ protected function process( - \Magento\Quote\Model\Quote\Address $address, - \Magento\Quote\Model\Quote\Address\Total $total, + Address $address, + Total $total, $item ) { $attributes = $this->weeeData->getProductWeeeAttributes( @@ -248,12 +257,12 @@ protected function process( /** * Process row amount based on FPT total amount configuration setting * - * @param \Magento\Quote\Model\Quote\Address\Total $total - * @param float $rowValueExclTax - * @param float $baseRowValueExclTax - * @param float $rowValueInclTax - * @param float $baseRowValueInclTax - * @return $this + * @param Total $total + * @param float $rowValueExclTax + * @param float $baseRowValueExclTax + * @param float $rowValueInclTax + * @param float $baseRowValueInclTax + * @return $this */ protected function processTotalAmount( $total, @@ -279,8 +288,7 @@ protected function processTotalAmount( } /** - * Increment and return counter. This function is intended to be used to generate temporary - * id for an item. + * Increment and return counter. This function is intended to be used to generate temporary id for an item. * * @return int */ @@ -292,25 +300,26 @@ protected function getNextIncrement() /** * Recalculate parent item amounts based on children results * - * @param \Magento\Quote\Model\Quote\Item\AbstractItem $item - * @return void - * + * @param AbstractItem $item + * @return void * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ - protected function recalculateParent(\Magento\Quote\Model\Quote\Item\AbstractItem $item) + protected function recalculateParent(AbstractItem $item) { - $associatedTaxables = []; + $associatedTaxables = [[]]; foreach ($item->getChildren() as $child) { - $associatedTaxables = array_merge($associatedTaxables, $child->getAssociatedTaxables()); + $associatedTaxables[] = $child->getAssociatedTaxables(); } - $item->setAssociatedTaxables($associatedTaxables); + $item->setAssociatedTaxables( + array_unique(array_merge(...$associatedTaxables)) + ); } /** * Reset information about Tax and Wee on FPT for shopping cart item * - * @param \Magento\Quote\Model\Quote\Item\AbstractItem $item - * @return void + * @param AbstractItem $item + * @return void */ protected function resetItemData($item) { @@ -332,24 +341,24 @@ protected function resetItemData($item) } /** - * @param \Magento\Quote\Model\Quote $quote - * @param \Magento\Quote\Model\Quote\Address\Total $total + * Return `null` instead of original empty array + * + * @param Quote $quote + * @param Total $total * @return array|null * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ - public function fetch(\Magento\Quote\Model\Quote $quote, \Magento\Quote\Model\Quote\Address\Total $total) + public function fetch(Quote $quote, Total $total) { return null; } /** - * Process model configuration array. - * This method can be used for changing totals collect sort order - * - * @param array $config - * @param Store $store - * @return array + * Process model configuration array. This method can be used for changing totals collect sort order * + * @param array $config + * @param Store $store + * @return array * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function processConfigArray($config, $store) @@ -360,7 +369,7 @@ public function processConfigArray($config, $store) /** * No aggregated label for fixed product tax * - * TODO: fix + * @TODO: fix * @return string */ public function getLabel()