From 00f13770e230b5ec4366fa429a2cc77a099f26f7 Mon Sep 17 00:00:00 2001 From: Andrii Kasian Date: Sun, 10 May 2020 21:15:52 -0500 Subject: [PATCH] Improve code quality. Return part of changes --- .../Model/ResourceModel/Index.php | 24 +++++----- .../Indexer/Product/Flat/FlatTableBuilder.php | 45 +++++++------------ .../Indexer/Product/Flat/TableBuilder.php | 4 +- .../Product/Link/Product/Collection.php | 18 +++++--- .../Model/ResourceModel/Stock/Status.php | 1 + .../Entity/Attribute/Collection.php | 9 ++-- .../Magento/TestFramework/Helper/Memory.php | 8 ++++ 7 files changed, 52 insertions(+), 57 deletions(-) diff --git a/app/code/Magento/AdvancedSearch/Model/ResourceModel/Index.php b/app/code/Magento/AdvancedSearch/Model/ResourceModel/Index.php index bf6a62f36e440..b20872da2f8e7 100644 --- a/app/code/Magento/AdvancedSearch/Model/ResourceModel/Index.php +++ b/app/code/Magento/AdvancedSearch/Model/ResourceModel/Index.php @@ -5,19 +5,18 @@ */ namespace Magento\AdvancedSearch\Model\ResourceModel; -use Magento\Catalog\Api\Data\CategoryInterface; -use Magento\Catalog\Model\Indexer\Category\Product\AbstractAction; -use Magento\Catalog\Model\Indexer\Product\Price\DimensionCollectionFactory; -use Magento\Framework\App\ObjectManager; -use Magento\Framework\EntityManager\MetadataPool; use Magento\Framework\Model\ResourceModel\Db\AbstractDb; +use Magento\Framework\Search\Request\IndexScopeResolverInterface; +use Magento\Store\Model\StoreManagerInterface; use Magento\Framework\Model\ResourceModel\Db\Context; +use Magento\Framework\EntityManager\MetadataPool; +use Magento\Catalog\Api\Data\CategoryInterface; +use Magento\Framework\App\ObjectManager; use Magento\Framework\Search\Request\Dimension; -use Magento\Framework\Search\Request\IndexScopeResolverInterface; +use Magento\Catalog\Model\Indexer\Category\Product\AbstractAction; use Magento\Framework\Search\Request\IndexScopeResolverInterface as TableResolver; +use Magento\Catalog\Model\Indexer\Product\Price\DimensionCollectionFactory; use Magento\Store\Model\Indexer\WebsiteDimensionProvider; -use Magento\Store\Model\Store; -use Magento\Store\Model\StoreManagerInterface; /** * @api @@ -56,7 +55,6 @@ class Index extends AbstractDb /** * Index constructor. - * * @param Context $context * @param StoreManagerInterface $storeManager * @param MetadataPool $metadataPool @@ -82,9 +80,7 @@ public function __construct( /** * Implementation of abstract construct - * * @return void - * @SuppressWarnings(PHPMD) * @since 100.1.0 */ protected function _construct() @@ -112,7 +108,7 @@ protected function _getCatalogProductPriceData($productIds = null) ['entity_id', 'customer_group_id', 'website_id', 'min_price'] ); if ($productIds) { - $select->where('entity_id IN (?)', $productIds, \Zend_Db::BIGINT_TYPE); + $select->where('entity_id IN (?)', $productIds); } $catalogProductIndexPriceSelect[] = $select; } @@ -163,7 +159,7 @@ public function getCategoryProductIndexData($storeId = null, $productIds = null) { $connection = $this->getConnection(); - $catalogCategoryProductDimension = new Dimension(Store::ENTITY, $storeId); + $catalogCategoryProductDimension = new Dimension(\Magento\Store\Model\Store::ENTITY, $storeId); $catalogCategoryProductTableName = $this->tableResolver->resolve( AbstractAction::MAIN_INDEX_TABLE, @@ -181,7 +177,7 @@ public function getCategoryProductIndexData($storeId = null, $productIds = null) ); if ($productIds) { - $select->where('product_id IN (?)', $productIds, \Zend_Db::BIGINT_TYPE); + $select->where('product_id IN (?)', $productIds); } $result = []; diff --git a/app/code/Magento/Catalog/Model/Indexer/Product/Flat/FlatTableBuilder.php b/app/code/Magento/Catalog/Model/Indexer/Product/Flat/FlatTableBuilder.php index e92778226aadd..d6decee249c04 100644 --- a/app/code/Magento/Catalog/Model/Indexer/Product/Flat/FlatTableBuilder.php +++ b/app/code/Magento/Catalog/Model/Indexer/Product/Flat/FlatTableBuilder.php @@ -6,18 +6,8 @@ namespace Magento\Catalog\Model\Indexer\Product\Flat; use Magento\Catalog\Api\Data\ProductInterface; -use Magento\Catalog\Helper\Product\Flat\Indexer; -use Magento\Catalog\Model\Product\Attribute\Source\Status; -use Magento\Eav\Model\Entity\Attribute; -use Magento\Framework\App\Config\ScopeConfigInterface; -use Magento\Framework\App\ObjectManager; use Magento\Framework\App\ResourceConnection; -use Magento\Framework\DB\Adapter\AdapterInterface; -use Magento\Framework\DB\Ddl\Table; -use Magento\Framework\DB\Select; use Magento\Framework\EntityManager\MetadataPool; -use Magento\Framework\Exception\LocalizedException; -use Magento\Store\Model\StoreManagerInterface; /** * Class for building flat index @@ -37,22 +27,22 @@ class FlatTableBuilder const XML_NODE_MAX_INDEX_COUNT = 'catalog/product/flat/max_index_count'; /** - * @var Indexer + * @var \Magento\Catalog\Helper\Product\Flat\Indexer */ protected $_productIndexerHelper; /** - * @var AdapterInterface + * @var \Magento\Framework\DB\Adapter\AdapterInterface */ protected $_connection; /** - * @var ScopeConfigInterface $config + * @var \Magento\Framework\App\Config\ScopeConfigInterface $config */ protected $_config; /** - * @var StoreManagerInterface + * @var \Magento\Store\Model\StoreManagerInterface */ protected $_storeManager; @@ -62,23 +52,23 @@ class FlatTableBuilder protected $_tableData; /** - * @var ResourceConnection + * @var \Magento\Framework\App\ResourceConnection */ protected $resource; /** - * @param Indexer $productIndexerHelper + * @param \Magento\Catalog\Helper\Product\Flat\Indexer $productIndexerHelper * @param ResourceConnection $resource - * @param ScopeConfigInterface $config - * @param StoreManagerInterface $storeManager + * @param \Magento\Framework\App\Config\ScopeConfigInterface $config + * @param \Magento\Store\Model\StoreManagerInterface $storeManager * @param TableDataInterface $tableData */ public function __construct( - Indexer $productIndexerHelper, - ResourceConnection $resource, - ScopeConfigInterface $config, - StoreManagerInterface $storeManager, - TableDataInterface $tableData + \Magento\Catalog\Helper\Product\Flat\Indexer $productIndexerHelper, + \Magento\Framework\App\ResourceConnection $resource, + \Magento\Framework\App\Config\ScopeConfigInterface $config, + \Magento\Store\Model\StoreManagerInterface $storeManager, + \Magento\Catalog\Model\Indexer\Product\Flat\TableDataInterface $tableData ) { $this->_productIndexerHelper = $productIndexerHelper; $this->resource = $resource; @@ -124,8 +114,7 @@ public function build($storeId, $changedIds, $valueFieldSuffix, $tableDropSuffix * * @param int|string $storeId * @return void - * @throws LocalizedException - * @throws \Zend_Db_Exception + * @throws \Magento\Framework\Exception\LocalizedException * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ @@ -139,7 +128,7 @@ protected function _createTemporaryFlatTable($storeId) self::XML_NODE_MAX_INDEX_COUNT ); if ($maxIndex && count($indexesNeed) > $maxIndex) { - throw new LocalizedException( + throw new \Magento\Framework\Exception\LocalizedException( __( 'The Flat Catalog module has a limit of %2$d filterable and/or sortable attributes.' . 'Currently there are %1$d of them.' @@ -152,7 +141,7 @@ protected function _createTemporaryFlatTable($storeId) $indexKeys = []; $indexProps = array_values($indexesNeed); - $upperPrimaryKey = strtoupper(AdapterInterface::INDEX_TYPE_PRIMARY); + $upperPrimaryKey = strtoupper(\Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_PRIMARY); foreach ($indexProps as $i => $indexProp) { $indexName = $this->_connection->getIndexName( $this->_getTemporaryTableName($this->_productIndexerHelper->getFlatTableName($storeId)), @@ -175,7 +164,7 @@ protected function _createTemporaryFlatTable($storeId) } $indexesNeed = array_combine($indexKeys, $indexProps); - /** @var $table Table */ + /** @var $table \Magento\Framework\DB\Ddl\Table */ $table = $this->_connection->newTable( $this->_getTemporaryTableName($this->_productIndexerHelper->getFlatTableName($storeId)) ); diff --git a/app/code/Magento/Catalog/Model/Indexer/Product/Flat/TableBuilder.php b/app/code/Magento/Catalog/Model/Indexer/Product/Flat/TableBuilder.php index c0632c6c246ce..376884cd88db5 100644 --- a/app/code/Magento/Catalog/Model/Indexer/Product/Flat/TableBuilder.php +++ b/app/code/Magento/Catalog/Model/Indexer/Product/Flat/TableBuilder.php @@ -233,9 +233,7 @@ protected function _fillTemporaryEntityTable($tableName, array $columns, array $ $select->from(['e' => $tableName], $columns); $onDuplicate = false; if (!empty($changedIds)) { - $select->where( - $this->_connection->quoteInto('e.entity_id IN (?)', $changedIds, \Zend_Db::BIGINT_TYPE) - ); + $select->where($this->_connection->quoteInto('e.entity_id IN (?)', $changedIds)); $onDuplicate = true; } $sql = $select->insertFromSelect($temporaryEntityTable, $columns, $onDuplicate); diff --git a/app/code/Magento/Catalog/Model/ResourceModel/Product/Link/Product/Collection.php b/app/code/Magento/Catalog/Model/ResourceModel/Product/Link/Product/Collection.php index 82cd3b54841a7..5a7ad23173f9f 100644 --- a/app/code/Magento/Catalog/Model/ResourceModel/Product/Link/Product/Collection.php +++ b/app/code/Magento/Catalog/Model/ResourceModel/Product/Link/Product/Collection.php @@ -9,7 +9,7 @@ use Magento\Catalog\Model\Indexer\Product\Flat\State; use Magento\Catalog\Model\Indexer\Product\Price\PriceTableResolver; use Magento\Catalog\Model\Product; -use Magento\Catalog\Model\Product\Link; +use Magento\Catalog\Model\Product\Link as LinkModel; use Magento\Catalog\Model\Product\OptionFactory; use Magento\Catalog\Model\ResourceModel\Category; use Magento\Catalog\Model\ResourceModel\Helper; @@ -53,7 +53,7 @@ class Collection extends \Magento\Catalog\Model\ResourceModel\Product\Collection /** * Store product link model * - * @var Link + * @var LinkModel */ protected $_linkModel; @@ -186,10 +186,10 @@ public function __construct( /** * Declare link model and initialize type attributes join * - * @param Link $linkModel + * @param LinkModel $linkModel * @return $this */ - public function setLinkModel(Link $linkModel) + public function setLinkModel(LinkModel $linkModel) { $this->_linkModel = $linkModel; if ($linkModel->getLinkTypeId()) { @@ -212,7 +212,7 @@ public function setIsStrongMode() /** * Retrieve collection link model * - * @return Link + * @return LinkModel */ public function getLinkModel() { @@ -239,7 +239,7 @@ public function setProduct(Product $product) /** * Retrieve collection base product object * - * @return Product + * @return \Magento\Catalog\Model\Product */ public function getProduct() { @@ -259,7 +259,11 @@ public function addExcludeProductFilter($products) $products = [$products]; } $this->_hasLinkFilter = true; - $this->getSelect()->where('links.linked_product_id NOT IN (?)', $products, \Zend_Db::BIGINT_TYPE); + $this->getSelect()->where( + 'links.linked_product_id NOT IN (?)', + $products, + \Zend_Db::BIGINT_TYPE + ); } return $this; } diff --git a/app/code/Magento/CatalogInventory/Model/ResourceModel/Stock/Status.php b/app/code/Magento/CatalogInventory/Model/ResourceModel/Stock/Status.php index 65b568fc39777..fcfc197f9036d 100644 --- a/app/code/Magento/CatalogInventory/Model/ResourceModel/Stock/Status.php +++ b/app/code/Magento/CatalogInventory/Model/ResourceModel/Stock/Status.php @@ -317,6 +317,7 @@ private function getWebsiteId($websiteId = null) /** * Retrieve Product(s) status for store + * * Return array where key is a product_id, value - status * * @param int[] $productIds diff --git a/app/code/Magento/Eav/Model/ResourceModel/Entity/Attribute/Collection.php b/app/code/Magento/Eav/Model/ResourceModel/Entity/Attribute/Collection.php index c7b0225576d1b..b354d8682e2d1 100644 --- a/app/code/Magento/Eav/Model/ResourceModel/Entity/Attribute/Collection.php +++ b/app/code/Magento/Eav/Model/ResourceModel/Entity/Attribute/Collection.php @@ -172,11 +172,11 @@ public function setAttributeSetFilter($setId) * * @param string $attributeSetName * @param string $entityTypeCode - * @return Collection - * @throws \Magento\Framework\Exception\LocalizedException + * @return void */ public function setAttributeSetFilterBySetName($attributeSetName, $entityTypeCode) { + //@codeCoverageIgnoreStart $entityTypeId = $this->eavConfig->getEntityType($entityTypeCode)->getId(); $this->join( ['entity_attribute' => $this->getTable('eav_entity_attribute')], @@ -190,8 +190,7 @@ public function setAttributeSetFilterBySetName($attributeSetName, $entityTypeCod $this->addFieldToFilter('attribute_set.entity_type_id', $entityTypeId); $this->addFieldToFilter('attribute_set.attribute_set_name', $attributeSetName); $this->setOrder('entity_attribute.sort_order', self::SORT_ORDER_ASC); - - return $this; + //@codeCoverageIgnoreEnd } /** @@ -440,7 +439,7 @@ protected function _addSetInfo() /** * Ad information about attribute sets to collection result data * - * @return AbstractCollection + * @return $this */ protected function _afterLoadData() { diff --git a/dev/tests/integration/framework/Magento/TestFramework/Helper/Memory.php b/dev/tests/integration/framework/Magento/TestFramework/Helper/Memory.php index 933d86fe6a4f5..6c8ff4640b0ba 100644 --- a/dev/tests/integration/framework/Magento/TestFramework/Helper/Memory.php +++ b/dev/tests/integration/framework/Magento/TestFramework/Helper/Memory.php @@ -53,6 +53,7 @@ public function getRealMemoryUsage() // fall back to the Unix command line $result = $this->_getUnixProcessMemoryUsage($pid); } catch (\Magento\Framework\Exception\LocalizedException $e) { + echo $e; // try to use the Windows command line // some ports of Unix commands on Windows, such as MinGW, have limited capabilities and cannot be used $result = $this->_getWinProcessMemoryUsage($pid); @@ -69,6 +70,13 @@ public function getRealMemoryUsage() */ protected function _getUnixProcessMemoryUsage($pid) { + if (!$this->isMacOS() + && ($content = @file_get_contents('/proc/' . (int) $pid . '/status')) + && \preg_match('/VmRSS:\s*(\d* \w)/mi', $content, $m) + && !empty($m[1]) + ) { + return self::convertToBytes($m[1]); + } // RSS - resident set size, the non-swapped physical memory $command = 'ps --pid %s --format rss --no-headers'; if ($this->isMacOS()) {