Skip to content

Commit

Permalink
Improve code quality. Return part of changes
Browse files Browse the repository at this point in the history
  • Loading branch information
kandy committed May 11, 2020
1 parent e099ad1 commit 00f1377
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 57 deletions.
24 changes: 10 additions & 14 deletions app/code/Magento/AdvancedSearch/Model/ResourceModel/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -56,7 +55,6 @@ class Index extends AbstractDb

/**
* Index constructor.
*
* @param Context $context
* @param StoreManagerInterface $storeManager
* @param MetadataPool $metadataPool
Expand All @@ -82,9 +80,7 @@ public function __construct(

/**
* Implementation of abstract construct
*
* @return void
* @SuppressWarnings(PHPMD)
* @since 100.1.0
*/
protected function _construct()
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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,
Expand All @@ -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 = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;

Expand All @@ -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;
Expand Down Expand Up @@ -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)
*/
Expand All @@ -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.'
Expand All @@ -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)),
Expand All @@ -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))
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -53,7 +53,7 @@ class Collection extends \Magento\Catalog\Model\ResourceModel\Product\Collection
/**
* Store product link model
*
* @var Link
* @var LinkModel
*/
protected $_linkModel;

Expand Down Expand Up @@ -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()) {
Expand All @@ -212,7 +212,7 @@ public function setIsStrongMode()
/**
* Retrieve collection link model
*
* @return Link
* @return LinkModel
*/
public function getLinkModel()
{
Expand All @@ -239,7 +239,7 @@ public function setProduct(Product $product)
/**
* Retrieve collection base product object
*
* @return Product
* @return \Magento\Catalog\Model\Product
*/
public function getProduct()
{
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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')],
Expand All @@ -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
}

/**
Expand Down Expand Up @@ -440,7 +439,7 @@ protected function _addSetInfo()
/**
* Ad information about attribute sets to collection result data
*
* @return AbstractCollection
* @return $this
*/
protected function _afterLoadData()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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()) {
Expand Down

0 comments on commit 00f1377

Please sign in to comment.