Skip to content

Commit 6587c57

Browse files
committed
Improve code quality
1 parent 00f1377 commit 6587c57

File tree

5 files changed

+54
-35
lines changed

5 files changed

+54
-35
lines changed

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

Lines changed: 40 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,19 @@
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\Framework\App\Config\ScopeConfigInterface;
911
use Magento\Framework\App\ResourceConnection;
12+
use Magento\Framework\DB\Adapter\AdapterInterface;
13+
use Magento\Framework\DB\Ddl\Table;
1014
use Magento\Framework\EntityManager\MetadataPool;
15+
use Magento\Framework\Exception\LocalizedException;
16+
use Magento\Framework\Exception\NoSuchEntityException;
17+
use Magento\Store\Model\StoreManagerInterface;
18+
use Magento\Catalog\Model\Product\Attribute\Source\Status;
19+
use Magento\Framework\App\ObjectManager;
20+
use Magento\Eav\Model\Entity\Attribute;
21+
use Magento\Framework\DB\Select;
1122

1223
/**
1324
* Class for building flat index
@@ -27,22 +38,22 @@ class FlatTableBuilder
2738
const XML_NODE_MAX_INDEX_COUNT = 'catalog/product/flat/max_index_count';
2839

2940
/**
30-
* @var \Magento\Catalog\Helper\Product\Flat\Indexer
41+
* @var Indexer
3142
*/
3243
protected $_productIndexerHelper;
3344

3445
/**
35-
* @var \Magento\Framework\DB\Adapter\AdapterInterface
46+
* @var AdapterInterface
3647
*/
3748
protected $_connection;
3849

3950
/**
40-
* @var \Magento\Framework\App\Config\ScopeConfigInterface $config
51+
* @var ScopeConfigInterface $config
4152
*/
4253
protected $_config;
4354

4455
/**
45-
* @var \Magento\Store\Model\StoreManagerInterface
56+
* @var StoreManagerInterface
4657
*/
4758
protected $_storeManager;
4859

@@ -52,23 +63,23 @@ class FlatTableBuilder
5263
protected $_tableData;
5364

5465
/**
55-
* @var \Magento\Framework\App\ResourceConnection
66+
* @var ResourceConnection
5667
*/
5768
protected $resource;
5869

5970
/**
60-
* @param \Magento\Catalog\Helper\Product\Flat\Indexer $productIndexerHelper
71+
* @param Indexer $productIndexerHelper
6172
* @param ResourceConnection $resource
62-
* @param \Magento\Framework\App\Config\ScopeConfigInterface $config
63-
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
73+
* @param ScopeConfigInterface $config
74+
* @param StoreManagerInterface $storeManager
6475
* @param TableDataInterface $tableData
6576
*/
6677
public function __construct(
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
78+
Indexer $productIndexerHelper,
79+
ResourceConnection $resource,
80+
ScopeConfigInterface $config,
81+
StoreManagerInterface $storeManager,
82+
TableDataInterface $tableData
7283
) {
7384
$this->_productIndexerHelper = $productIndexerHelper;
7485
$this->resource = $resource;
@@ -114,7 +125,7 @@ public function build($storeId, $changedIds, $valueFieldSuffix, $tableDropSuffix
114125
*
115126
* @param int|string $storeId
116127
* @return void
117-
* @throws \Magento\Framework\Exception\LocalizedException
128+
* @throws LocalizedException
118129
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
119130
* @SuppressWarnings(PHPMD.NPathComplexity)
120131
*/
@@ -128,7 +139,7 @@ protected function _createTemporaryFlatTable($storeId)
128139
self::XML_NODE_MAX_INDEX_COUNT
129140
);
130141
if ($maxIndex && count($indexesNeed) > $maxIndex) {
131-
throw new \Magento\Framework\Exception\LocalizedException(
142+
throw new LocalizedException(
132143
__(
133144
'The Flat Catalog module has a limit of %2$d filterable and/or sortable attributes.'
134145
. 'Currently there are %1$d of them.'
@@ -141,7 +152,7 @@ protected function _createTemporaryFlatTable($storeId)
141152

142153
$indexKeys = [];
143154
$indexProps = array_values($indexesNeed);
144-
$upperPrimaryKey = strtoupper(\Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_PRIMARY);
155+
$upperPrimaryKey = strtoupper(AdapterInterface::INDEX_TYPE_PRIMARY);
145156
foreach ($indexProps as $i => $indexProp) {
146157
$indexName = $this->_connection->getIndexName(
147158
$this->_getTemporaryTableName($this->_productIndexerHelper->getFlatTableName($storeId)),
@@ -164,7 +175,7 @@ protected function _createTemporaryFlatTable($storeId)
164175
}
165176
$indexesNeed = array_combine($indexKeys, $indexProps);
166177

167-
/** @var $table \Magento\Framework\DB\Ddl\Table */
178+
/** @var $table Table */
168179
$table = $this->_connection->newTable(
169180
$this->_getTemporaryTableName($this->_productIndexerHelper->getFlatTableName($storeId))
170181
);
@@ -212,7 +223,7 @@ protected function _createTemporaryFlatTable($storeId)
212223
* @param string $valueFieldSuffix
213224
* @return void
214225
* @throws LocalizedException
215-
* @throws \Magento\Framework\Exception\NoSuchEntityException
226+
* @throws NoSuchEntityException
216227
*/
217228
protected function _fillTemporaryFlatTable(array $tables, $storeId, $valueFieldSuffix)
218229
{
@@ -228,8 +239,8 @@ protected function _fillTemporaryFlatTable(array $tables, $storeId, $valueFieldS
228239
$websiteId = (int)$this->_storeManager->getStore($storeId)->getWebsiteId();
229240

230241
unset($tables[$entityTableName]);
231-
232-
$allColumns = array_values(
242+
$allColumns = [];
243+
$allColumns[] = array_values(
233244
array_unique(
234245
array_merge(['entity_id', $linkField, 'type_id', 'attribute_set_id'], $columnsList)
235246
)
@@ -278,7 +289,7 @@ protected function _fillTemporaryFlatTable(array $tables, $storeId, $valueFieldS
278289
sprintf('e.%1$s = %2$s.%1$s', $linkField, $temporaryTableName),
279290
$columnsNames
280291
);
281-
$allColumns = array_merge($allColumns, $columnsNames);
292+
$allColumns[] = $columnsNames;
282293

283294
foreach ($columnsNames as $name) {
284295
$columnValueName = $name . $valueFieldSuffix;
@@ -292,10 +303,10 @@ protected function _fillTemporaryFlatTable(array $tables, $storeId, $valueFieldS
292303
sprintf('e.%1$s = %2$s.%1$s', $linkField, $temporaryValueTableName),
293304
$columnValueNames
294305
);
295-
$allColumns = array_merge($allColumns, $columnValueNames);
306+
$allColumns[] = $columnValueNames;
296307
}
297308
}
298-
$sql = $select->insertFromSelect($temporaryFlatTableName, $allColumns, false);
309+
$sql = $select->insertFromSelect($temporaryFlatTableName, array_merge(...$allColumns), false);
299310
$this->_connection->query($sql);
300311
}
301312

@@ -368,8 +379,12 @@ protected function _updateTemporaryTableByStoreValues(
368379
)->where($columnValue . ' IS NOT NULL');
369380
if (!empty($changedIds)) {
370381
$select->where(
371-
$this->_connection->quoteInto('et.entity_id IN (?)', $changedIds, \Zend_Db::BIGINT_TYPE))
372-
;
382+
$this->_connection->quoteInto(
383+
'et.entity_id IN (?)',
384+
$changedIds,
385+
\Zend_Db::BIGINT_TYPE
386+
)
387+
);
373388
}
374389
$sql = $select->crossUpdateFromSelect(['et' => $temporaryFlatTableName]);
375390
$this->_connection->query($sql);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use Magento\Store\Model\Store;
1010

1111
/**
12-
* Class TableBuilder
12+
* Prepare temporary tables structure for product flat indexer
1313
*
1414
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1515
*/

app/code/Magento/Catalog/Model/Indexer/Product/Price/AbstractAction.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,8 @@ protected function getIndexTargetTable()
517517
}
518518

519519
/**
520+
* Return Product ID field name
521+
*
520522
* @return string
521523
*/
522524
protected function getProductIdFieldName()
@@ -553,6 +555,7 @@ private function getProductsTypes(array $changedIds = [])
553555

554556
/**
555557
* Get parent products types
558+
*
556559
* Used for add composite products to reindex if we have only simple products in changed ids set
557560
*
558561
* @param array $productsIds

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,10 +347,18 @@ protected function _joinLinks()
347347
$linkField = $this->getLinkField();
348348
if ($this->productIds) {
349349
if ($this->_isStrongMode) {
350-
$this->getSelect()->where('links.product_id in (?)', $this->productIds, \Zend_Db::BIGINT_TYPE);
350+
$this->getSelect()->where(
351+
'links.product_id in (?)',
352+
$this->productIds,
353+
\Zend_Db::BIGINT_TYPE
354+
);
351355
} else {
352356
$joinType = 'joinLeft';
353-
$joinCondition[] = $connection->quoteInto('links.product_id in (?)', $this->productIds, \Zend_Db::BIGINT_TYPE);
357+
$joinCondition[] = $connection->quoteInto(
358+
'links.product_id in (?)',
359+
$this->productIds,
360+
\Zend_Db::BIGINT_TYPE
361+
);
354362
}
355363
if (count($this->productIds) === 1) {
356364
$this->addFieldToFilter(

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,6 @@ public function getRealMemoryUsage()
7070
*/
7171
protected function _getUnixProcessMemoryUsage($pid)
7272
{
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-
}
8073
// RSS - resident set size, the non-swapped physical memory
8174
$command = 'ps --pid %s --format rss --no-headers';
8275
if ($this->isMacOS()) {

0 commit comments

Comments
 (0)