Skip to content

Commit 00f1377

Browse files
committed
Improve code quality. Return part of changes
1 parent e099ad1 commit 00f1377

File tree

7 files changed

+52
-57
lines changed

7 files changed

+52
-57
lines changed

app/code/Magento/AdvancedSearch/Model/ResourceModel/Index.php

+10-14
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,18 @@
55
*/
66
namespace Magento\AdvancedSearch\Model\ResourceModel;
77

8-
use Magento\Catalog\Api\Data\CategoryInterface;
9-
use Magento\Catalog\Model\Indexer\Category\Product\AbstractAction;
10-
use Magento\Catalog\Model\Indexer\Product\Price\DimensionCollectionFactory;
11-
use Magento\Framework\App\ObjectManager;
12-
use Magento\Framework\EntityManager\MetadataPool;
138
use Magento\Framework\Model\ResourceModel\Db\AbstractDb;
9+
use Magento\Framework\Search\Request\IndexScopeResolverInterface;
10+
use Magento\Store\Model\StoreManagerInterface;
1411
use Magento\Framework\Model\ResourceModel\Db\Context;
12+
use Magento\Framework\EntityManager\MetadataPool;
13+
use Magento\Catalog\Api\Data\CategoryInterface;
14+
use Magento\Framework\App\ObjectManager;
1515
use Magento\Framework\Search\Request\Dimension;
16-
use Magento\Framework\Search\Request\IndexScopeResolverInterface;
16+
use Magento\Catalog\Model\Indexer\Category\Product\AbstractAction;
1717
use Magento\Framework\Search\Request\IndexScopeResolverInterface as TableResolver;
18+
use Magento\Catalog\Model\Indexer\Product\Price\DimensionCollectionFactory;
1819
use Magento\Store\Model\Indexer\WebsiteDimensionProvider;
19-
use Magento\Store\Model\Store;
20-
use Magento\Store\Model\StoreManagerInterface;
2120

2221
/**
2322
* @api
@@ -56,7 +55,6 @@ class Index extends AbstractDb
5655

5756
/**
5857
* Index constructor.
59-
*
6058
* @param Context $context
6159
* @param StoreManagerInterface $storeManager
6260
* @param MetadataPool $metadataPool
@@ -82,9 +80,7 @@ public function __construct(
8280

8381
/**
8482
* Implementation of abstract construct
85-
*
8683
* @return void
87-
* @SuppressWarnings(PHPMD)
8884
* @since 100.1.0
8985
*/
9086
protected function _construct()
@@ -112,7 +108,7 @@ protected function _getCatalogProductPriceData($productIds = null)
112108
['entity_id', 'customer_group_id', 'website_id', 'min_price']
113109
);
114110
if ($productIds) {
115-
$select->where('entity_id IN (?)', $productIds, \Zend_Db::BIGINT_TYPE);
111+
$select->where('entity_id IN (?)', $productIds);
116112
}
117113
$catalogProductIndexPriceSelect[] = $select;
118114
}
@@ -163,7 +159,7 @@ public function getCategoryProductIndexData($storeId = null, $productIds = null)
163159
{
164160
$connection = $this->getConnection();
165161

166-
$catalogCategoryProductDimension = new Dimension(Store::ENTITY, $storeId);
162+
$catalogCategoryProductDimension = new Dimension(\Magento\Store\Model\Store::ENTITY, $storeId);
167163

168164
$catalogCategoryProductTableName = $this->tableResolver->resolve(
169165
AbstractAction::MAIN_INDEX_TABLE,
@@ -181,7 +177,7 @@ public function getCategoryProductIndexData($storeId = null, $productIds = null)
181177
);
182178

183179
if ($productIds) {
184-
$select->where('product_id IN (?)', $productIds, \Zend_Db::BIGINT_TYPE);
180+
$select->where('product_id IN (?)', $productIds);
185181
}
186182

187183
$result = [];

app/code/Magento/Catalog/Model/Indexer/Product/Flat/FlatTableBuilder.php

+17-28
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,8 @@
66
namespace Magento\Catalog\Model\Indexer\Product\Flat;
77

88
use Magento\Catalog\Api\Data\ProductInterface;
9-
use Magento\Catalog\Helper\Product\Flat\Indexer;
10-
use Magento\Catalog\Model\Product\Attribute\Source\Status;
11-
use Magento\Eav\Model\Entity\Attribute;
12-
use Magento\Framework\App\Config\ScopeConfigInterface;
13-
use Magento\Framework\App\ObjectManager;
149
use Magento\Framework\App\ResourceConnection;
15-
use Magento\Framework\DB\Adapter\AdapterInterface;
16-
use Magento\Framework\DB\Ddl\Table;
17-
use Magento\Framework\DB\Select;
1810
use Magento\Framework\EntityManager\MetadataPool;
19-
use Magento\Framework\Exception\LocalizedException;
20-
use Magento\Store\Model\StoreManagerInterface;
2111

2212
/**
2313
* Class for building flat index
@@ -37,22 +27,22 @@ class FlatTableBuilder
3727
const XML_NODE_MAX_INDEX_COUNT = 'catalog/product/flat/max_index_count';
3828

3929
/**
40-
* @var Indexer
30+
* @var \Magento\Catalog\Helper\Product\Flat\Indexer
4131
*/
4232
protected $_productIndexerHelper;
4333

4434
/**
45-
* @var AdapterInterface
35+
* @var \Magento\Framework\DB\Adapter\AdapterInterface
4636
*/
4737
protected $_connection;
4838

4939
/**
50-
* @var ScopeConfigInterface $config
40+
* @var \Magento\Framework\App\Config\ScopeConfigInterface $config
5141
*/
5242
protected $_config;
5343

5444
/**
55-
* @var StoreManagerInterface
45+
* @var \Magento\Store\Model\StoreManagerInterface
5646
*/
5747
protected $_storeManager;
5848

@@ -62,23 +52,23 @@ class FlatTableBuilder
6252
protected $_tableData;
6353

6454
/**
65-
* @var ResourceConnection
55+
* @var \Magento\Framework\App\ResourceConnection
6656
*/
6757
protected $resource;
6858

6959
/**
70-
* @param Indexer $productIndexerHelper
60+
* @param \Magento\Catalog\Helper\Product\Flat\Indexer $productIndexerHelper
7161
* @param ResourceConnection $resource
72-
* @param ScopeConfigInterface $config
73-
* @param StoreManagerInterface $storeManager
62+
* @param \Magento\Framework\App\Config\ScopeConfigInterface $config
63+
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
7464
* @param TableDataInterface $tableData
7565
*/
7666
public function __construct(
77-
Indexer $productIndexerHelper,
78-
ResourceConnection $resource,
79-
ScopeConfigInterface $config,
80-
StoreManagerInterface $storeManager,
81-
TableDataInterface $tableData
67+
\Magento\Catalog\Helper\Product\Flat\Indexer $productIndexerHelper,
68+
\Magento\Framework\App\ResourceConnection $resource,
69+
\Magento\Framework\App\Config\ScopeConfigInterface $config,
70+
\Magento\Store\Model\StoreManagerInterface $storeManager,
71+
\Magento\Catalog\Model\Indexer\Product\Flat\TableDataInterface $tableData
8272
) {
8373
$this->_productIndexerHelper = $productIndexerHelper;
8474
$this->resource = $resource;
@@ -124,8 +114,7 @@ public function build($storeId, $changedIds, $valueFieldSuffix, $tableDropSuffix
124114
*
125115
* @param int|string $storeId
126116
* @return void
127-
* @throws LocalizedException
128-
* @throws \Zend_Db_Exception
117+
* @throws \Magento\Framework\Exception\LocalizedException
129118
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
130119
* @SuppressWarnings(PHPMD.NPathComplexity)
131120
*/
@@ -139,7 +128,7 @@ protected function _createTemporaryFlatTable($storeId)
139128
self::XML_NODE_MAX_INDEX_COUNT
140129
);
141130
if ($maxIndex && count($indexesNeed) > $maxIndex) {
142-
throw new LocalizedException(
131+
throw new \Magento\Framework\Exception\LocalizedException(
143132
__(
144133
'The Flat Catalog module has a limit of %2$d filterable and/or sortable attributes.'
145134
. 'Currently there are %1$d of them.'
@@ -152,7 +141,7 @@ protected function _createTemporaryFlatTable($storeId)
152141

153142
$indexKeys = [];
154143
$indexProps = array_values($indexesNeed);
155-
$upperPrimaryKey = strtoupper(AdapterInterface::INDEX_TYPE_PRIMARY);
144+
$upperPrimaryKey = strtoupper(\Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_PRIMARY);
156145
foreach ($indexProps as $i => $indexProp) {
157146
$indexName = $this->_connection->getIndexName(
158147
$this->_getTemporaryTableName($this->_productIndexerHelper->getFlatTableName($storeId)),
@@ -175,7 +164,7 @@ protected function _createTemporaryFlatTable($storeId)
175164
}
176165
$indexesNeed = array_combine($indexKeys, $indexProps);
177166

178-
/** @var $table Table */
167+
/** @var $table \Magento\Framework\DB\Ddl\Table */
179168
$table = $this->_connection->newTable(
180169
$this->_getTemporaryTableName($this->_productIndexerHelper->getFlatTableName($storeId))
181170
);

app/code/Magento/Catalog/Model/Indexer/Product/Flat/TableBuilder.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,7 @@ protected function _fillTemporaryEntityTable($tableName, array $columns, array $
233233
$select->from(['e' => $tableName], $columns);
234234
$onDuplicate = false;
235235
if (!empty($changedIds)) {
236-
$select->where(
237-
$this->_connection->quoteInto('e.entity_id IN (?)', $changedIds, \Zend_Db::BIGINT_TYPE)
238-
);
236+
$select->where($this->_connection->quoteInto('e.entity_id IN (?)', $changedIds));
239237
$onDuplicate = true;
240238
}
241239
$sql = $select->insertFromSelect($temporaryEntityTable, $columns, $onDuplicate);

app/code/Magento/Catalog/Model/ResourceModel/Product/Link/Product/Collection.php

+11-7
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use Magento\Catalog\Model\Indexer\Product\Flat\State;
1010
use Magento\Catalog\Model\Indexer\Product\Price\PriceTableResolver;
1111
use Magento\Catalog\Model\Product;
12-
use Magento\Catalog\Model\Product\Link;
12+
use Magento\Catalog\Model\Product\Link as LinkModel;
1313
use Magento\Catalog\Model\Product\OptionFactory;
1414
use Magento\Catalog\Model\ResourceModel\Category;
1515
use Magento\Catalog\Model\ResourceModel\Helper;
@@ -53,7 +53,7 @@ class Collection extends \Magento\Catalog\Model\ResourceModel\Product\Collection
5353
/**
5454
* Store product link model
5555
*
56-
* @var Link
56+
* @var LinkModel
5757
*/
5858
protected $_linkModel;
5959

@@ -186,10 +186,10 @@ public function __construct(
186186
/**
187187
* Declare link model and initialize type attributes join
188188
*
189-
* @param Link $linkModel
189+
* @param LinkModel $linkModel
190190
* @return $this
191191
*/
192-
public function setLinkModel(Link $linkModel)
192+
public function setLinkModel(LinkModel $linkModel)
193193
{
194194
$this->_linkModel = $linkModel;
195195
if ($linkModel->getLinkTypeId()) {
@@ -212,7 +212,7 @@ public function setIsStrongMode()
212212
/**
213213
* Retrieve collection link model
214214
*
215-
* @return Link
215+
* @return LinkModel
216216
*/
217217
public function getLinkModel()
218218
{
@@ -239,7 +239,7 @@ public function setProduct(Product $product)
239239
/**
240240
* Retrieve collection base product object
241241
*
242-
* @return Product
242+
* @return \Magento\Catalog\Model\Product
243243
*/
244244
public function getProduct()
245245
{
@@ -259,7 +259,11 @@ public function addExcludeProductFilter($products)
259259
$products = [$products];
260260
}
261261
$this->_hasLinkFilter = true;
262-
$this->getSelect()->where('links.linked_product_id NOT IN (?)', $products, \Zend_Db::BIGINT_TYPE);
262+
$this->getSelect()->where(
263+
'links.linked_product_id NOT IN (?)',
264+
$products,
265+
\Zend_Db::BIGINT_TYPE
266+
);
263267
}
264268
return $this;
265269
}

app/code/Magento/CatalogInventory/Model/ResourceModel/Stock/Status.php

+1
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ private function getWebsiteId($websiteId = null)
317317

318318
/**
319319
* Retrieve Product(s) status for store
320+
*
320321
* Return array where key is a product_id, value - status
321322
*
322323
* @param int[] $productIds

app/code/Magento/Eav/Model/ResourceModel/Entity/Attribute/Collection.php

+4-5
Original file line numberDiff line numberDiff line change
@@ -172,11 +172,11 @@ public function setAttributeSetFilter($setId)
172172
*
173173
* @param string $attributeSetName
174174
* @param string $entityTypeCode
175-
* @return Collection
176-
* @throws \Magento\Framework\Exception\LocalizedException
175+
* @return void
177176
*/
178177
public function setAttributeSetFilterBySetName($attributeSetName, $entityTypeCode)
179178
{
179+
//@codeCoverageIgnoreStart
180180
$entityTypeId = $this->eavConfig->getEntityType($entityTypeCode)->getId();
181181
$this->join(
182182
['entity_attribute' => $this->getTable('eav_entity_attribute')],
@@ -190,8 +190,7 @@ public function setAttributeSetFilterBySetName($attributeSetName, $entityTypeCod
190190
$this->addFieldToFilter('attribute_set.entity_type_id', $entityTypeId);
191191
$this->addFieldToFilter('attribute_set.attribute_set_name', $attributeSetName);
192192
$this->setOrder('entity_attribute.sort_order', self::SORT_ORDER_ASC);
193-
194-
return $this;
193+
//@codeCoverageIgnoreEnd
195194
}
196195

197196
/**
@@ -440,7 +439,7 @@ protected function _addSetInfo()
440439
/**
441440
* Ad information about attribute sets to collection result data
442441
*
443-
* @return AbstractCollection
442+
* @return $this
444443
*/
445444
protected function _afterLoadData()
446445
{

dev/tests/integration/framework/Magento/TestFramework/Helper/Memory.php

+8
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public function getRealMemoryUsage()
5353
// fall back to the Unix command line
5454
$result = $this->_getUnixProcessMemoryUsage($pid);
5555
} catch (\Magento\Framework\Exception\LocalizedException $e) {
56+
echo $e;
5657
// try to use the Windows command line
5758
// some ports of Unix commands on Windows, such as MinGW, have limited capabilities and cannot be used
5859
$result = $this->_getWinProcessMemoryUsage($pid);
@@ -69,6 +70,13 @@ public function getRealMemoryUsage()
6970
*/
7071
protected function _getUnixProcessMemoryUsage($pid)
7172
{
73+
if (!$this->isMacOS()
74+
&& ($content = @file_get_contents('/proc/' . (int) $pid . '/status'))
75+
&& \preg_match('/VmRSS:\s*(\d* \w)/mi', $content, $m)
76+
&& !empty($m[1])
77+
) {
78+
return self::convertToBytes($m[1]);
79+
}
7280
// RSS - resident set size, the non-swapped physical memory
7381
$command = 'ps --pid %s --format rss --no-headers';
7482
if ($this->isMacOS()) {

0 commit comments

Comments
 (0)