Skip to content

Commit e099ad1

Browse files
committed
Improve code quality
1 parent f2bba37 commit e099ad1

File tree

16 files changed

+365
-253
lines changed

16 files changed

+365
-253
lines changed

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

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,19 @@
55
*/
66
namespace Magento\AdvancedSearch\Model\ResourceModel;
77

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

2122
/**
2223
* @api
@@ -55,6 +56,7 @@ class Index extends AbstractDb
5556

5657
/**
5758
* Index constructor.
59+
*
5860
* @param Context $context
5961
* @param StoreManagerInterface $storeManager
6062
* @param MetadataPool $metadataPool
@@ -80,7 +82,9 @@ public function __construct(
8082

8183
/**
8284
* Implementation of abstract construct
85+
*
8386
* @return void
87+
* @SuppressWarnings(PHPMD)
8488
* @since 100.1.0
8589
*/
8690
protected function _construct()
@@ -159,7 +163,7 @@ public function getCategoryProductIndexData($storeId = null, $productIds = null)
159163
{
160164
$connection = $this->getConnection();
161165

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

164168
$catalogCategoryProductTableName = $this->tableResolver->resolve(
165169
AbstractAction::MAIN_INDEX_TABLE,

app/code/Magento/Catalog/Model/Indexer/Category/Flat/AbstractAction.php

Lines changed: 46 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,21 @@
66

77
namespace Magento\Catalog\Model\Indexer\Category\Flat;
88

9+
use Magento\Catalog\Api\Data\CategoryInterface;
10+
use Magento\Catalog\Model\Category;
11+
use Magento\Catalog\Model\ResourceModel\Helper;
12+
use Magento\Framework\App\ObjectManager;
913
use Magento\Framework\App\ResourceConnection;
14+
use Magento\Framework\DB\Adapter\AdapterInterface;
15+
use Magento\Framework\DB\Ddl\Table;
16+
use Magento\Framework\EntityManager\EntityMetadata;
17+
use Magento\Store\Model\Store;
18+
use Magento\Store\Model\StoreManagerInterface;
1019

1120
/**
1221
* Abstract action class for category flat indexers.
22+
*
23+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1324
*/
1425
class AbstractAction
1526
{
@@ -31,14 +42,14 @@ class AbstractAction
3142
protected $resource;
3243

3344
/**
34-
* @var \Magento\Store\Model\StoreManagerInterface
45+
* @var StoreManagerInterface
3546
*/
3647
protected $storeManager;
3748

3849
/**
3950
* Catalog resource helper
4051
*
41-
* @var \Magento\Catalog\Model\ResourceModel\Helper
52+
* @var Helper
4253
*/
4354
protected $resourceHelper;
4455

@@ -50,12 +61,12 @@ class AbstractAction
5061
protected $columns = [];
5162

5263
/**
53-
* @var \Magento\Framework\DB\Adapter\AdapterInterface
64+
* @var AdapterInterface
5465
*/
5566
protected $connection;
5667

5768
/**
58-
* @var \Magento\Framework\EntityManager\EntityMetadata
69+
* @var EntityMetadata
5970
*/
6071
protected $categoryMetadata;
6172

@@ -68,13 +79,13 @@ class AbstractAction
6879

6980
/**
7081
* @param ResourceConnection $resource
71-
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
72-
* @param \Magento\Catalog\Model\ResourceModel\Helper $resourceHelper
82+
* @param StoreManagerInterface $storeManager
83+
* @param Helper $resourceHelper
7384
*/
7485
public function __construct(
7586
ResourceConnection $resource,
76-
\Magento\Store\Model\StoreManagerInterface $storeManager,
77-
\Magento\Catalog\Model\ResourceModel\Helper $resourceHelper
87+
StoreManagerInterface $storeManager,
88+
Helper $resourceHelper
7889
) {
7990
$this->resource = $resource;
8091
$this->connection = $resource->getConnection();
@@ -110,23 +121,22 @@ public function getColumns()
110121
* @param integer $storeId
111122
* @return string
112123
*/
113-
public function getMainStoreTable($storeId = \Magento\Store\Model\Store::DEFAULT_STORE_ID)
124+
public function getMainStoreTable($storeId = Store::DEFAULT_STORE_ID)
114125
{
115126
if (is_string($storeId)) {
116127
$storeId = (int) $storeId;
117128
}
118129

119130
$suffix = sprintf('store_%d', $storeId);
120-
$table = $this->connection->getTableName($this->getTableName('catalog_category_flat_' . $suffix));
121-
122-
return $table;
131+
return $this->connection->getTableName($this->getTableName('catalog_category_flat_' . $suffix));
123132
}
124133

125134
/**
126135
* Return structure for flat catalog table
127136
*
128137
* @param string $tableName
129-
* @return \Magento\Framework\DB\Ddl\Table
138+
* @return Table
139+
* @throws \Zend_Db_Exception
130140
*/
131141
protected function getFlatTableStructure($tableName)
132142
{
@@ -139,10 +149,10 @@ protected function getFlatTableStructure($tableName)
139149
//Adding columns
140150
foreach ($this->getColumns() as $fieldName => $fieldProp) {
141151
$default = $fieldProp['default'];
142-
if ($fieldProp['type'][0] == \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP
152+
if ($fieldProp['type'][0] == Table::TYPE_TIMESTAMP
143153
&& $default == 'CURRENT_TIMESTAMP'
144154
) {
145-
$default = \Magento\Framework\DB\Ddl\Table::TIMESTAMP_INIT;
155+
$default = Table::TIMESTAMP_INIT;
146156
}
147157
$table->addColumn(
148158
$fieldName,
@@ -205,37 +215,37 @@ protected function getStaticColumns()
205215
$ddlType = $this->resourceHelper->getDdlTypeByColumnType($column['DATA_TYPE']);
206216
$column['DEFAULT'] = trim($column['DEFAULT'], "' ");
207217
switch ($ddlType) {
208-
case \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT:
209-
case \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER:
210-
case \Magento\Framework\DB\Ddl\Table::TYPE_BIGINT:
218+
case Table::TYPE_SMALLINT:
219+
case Table::TYPE_INTEGER:
220+
case Table::TYPE_BIGINT:
211221
$isUnsigned = (bool)$column['UNSIGNED'];
212222
if ($column['DEFAULT'] === '') {
213223
$column['DEFAULT'] = null;
214224
}
215225

216226
$options = null;
217227
if ($column['SCALE'] > 0) {
218-
$ddlType = \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL;
228+
$ddlType = Table::TYPE_DECIMAL;
219229
} else {
220230
break;
221231
}
222232
// fall-through intentional
223-
case \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL:
233+
case Table::TYPE_DECIMAL:
224234
$options = $column['PRECISION'] . ',' . $column['SCALE'];
225235
$isUnsigned = null;
226236
if ($column['DEFAULT'] === '') {
227237
$column['DEFAULT'] = null;
228238
}
229239
break;
230-
case \Magento\Framework\DB\Ddl\Table::TYPE_TEXT:
240+
case Table::TYPE_TEXT:
231241
$options = $column['LENGTH'];
232242
$isUnsigned = null;
233243
break;
234-
case \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP:
244+
case Table::TYPE_TIMESTAMP:
235245
$options = null;
236246
$isUnsigned = null;
237247
break;
238-
case \Magento\Framework\DB\Ddl\Table::TYPE_DATETIME:
248+
case Table::TYPE_DATETIME:
239249
$isUnsigned = null;
240250
break;
241251
}
@@ -248,7 +258,7 @@ protected function getStaticColumns()
248258
];
249259
}
250260
$columns['store_id'] = [
251-
'type' => [\Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, 5],
261+
'type' => [Table::TYPE_SMALLINT, 5],
252262
'unsigned' => true,
253263
'nullable' => false,
254264
'default' => '0',
@@ -274,7 +284,7 @@ protected function getEavColumns()
274284
switch ($attribute['backend_type']) {
275285
case 'varchar':
276286
$columns[$attribute['attribute_code']] = [
277-
'type' => [\Magento\Framework\DB\Ddl\Table::TYPE_TEXT, 255],
287+
'type' => [Table::TYPE_TEXT, 255],
278288
'unsigned' => null,
279289
'nullable' => true,
280290
'default' => null,
@@ -283,7 +293,7 @@ protected function getEavColumns()
283293
break;
284294
case 'int':
285295
$columns[$attribute['attribute_code']] = [
286-
'type' => [\Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, null],
296+
'type' => [Table::TYPE_INTEGER, null],
287297
'unsigned' => null,
288298
'nullable' => true,
289299
'default' => null,
@@ -292,7 +302,7 @@ protected function getEavColumns()
292302
break;
293303
case 'text':
294304
$columns[$attribute['attribute_code']] = [
295-
'type' => [\Magento\Framework\DB\Ddl\Table::TYPE_TEXT, '64k'],
305+
'type' => [Table::TYPE_TEXT, '64k'],
296306
'unsigned' => null,
297307
'nullable' => true,
298308
'default' => null,
@@ -301,7 +311,7 @@ protected function getEavColumns()
301311
break;
302312
case 'datetime':
303313
$columns[$attribute['attribute_code']] = [
304-
'type' => [\Magento\Framework\DB\Ddl\Table::TYPE_DATETIME, null],
314+
'type' => [Table::TYPE_DATETIME, null],
305315
'unsigned' => null,
306316
'nullable' => true,
307317
'default' => null,
@@ -310,7 +320,7 @@ protected function getEavColumns()
310320
break;
311321
case 'decimal':
312322
$columns[$attribute['attribute_code']] = [
313-
'type' => [\Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, '12,4'],
323+
'type' => [Table::TYPE_DECIMAL, '12,4'],
314324
'unsigned' => null,
315325
'nullable' => true,
316326
'default' => null,
@@ -346,7 +356,7 @@ protected function getAttributes()
346356
$this->connection->getTableName(
347357
$this->getTableName('eav_entity_type')
348358
) . '.entity_type_code = ?',
349-
\Magento\Catalog\Model\Category::ENTITY
359+
Category::ENTITY
350360
);
351361
$this->attributeCodes = [];
352362
foreach ($this->connection->fetchAll($select) as $attribute) {
@@ -464,7 +474,7 @@ protected function getAttributeTypeValues($type, $entityIds, $storeId)
464474
\Zend_Db::BIGINT_TYPE
465475
)->where(
466476
'def.store_id IN (?)',
467-
[\Magento\Store\Model\Store::DEFAULT_STORE_ID, $storeId],
477+
[Store::DEFAULT_STORE_ID, $storeId],
468478
\Zend_Db::BIGINT_TYPE
469479
);
470480

@@ -504,14 +514,14 @@ protected function getTableName($name)
504514
/**
505515
* Get category metadata instance.
506516
*
507-
* @return \Magento\Framework\EntityManager\EntityMetadata
517+
* @return EntityMetadata
508518
*/
509519
private function getCategoryMetadata()
510520
{
511521
if (null === $this->categoryMetadata) {
512-
$metadataPool = \Magento\Framework\App\ObjectManager::getInstance()
522+
$metadataPool = ObjectManager::getInstance()
513523
->get(\Magento\Framework\EntityManager\MetadataPool::class);
514-
$this->categoryMetadata = $metadataPool->getMetadata(\Magento\Catalog\Api\Data\CategoryInterface::class);
524+
$this->categoryMetadata = $metadataPool->getMetadata(CategoryInterface::class);
515525
}
516526
return $this->categoryMetadata;
517527
}
@@ -524,8 +534,8 @@ private function getCategoryMetadata()
524534
private function getSkipStaticColumns()
525535
{
526536
if (null === $this->skipStaticColumns) {
527-
$provider = \Magento\Framework\App\ObjectManager::getInstance()
528-
->get(\Magento\Catalog\Model\Indexer\Category\Flat\SkipStaticColumnsProvider::class);
537+
$provider = ObjectManager::getInstance()
538+
->get(SkipStaticColumnsProvider::class);
529539
$this->skipStaticColumns = $provider->get();
530540
}
531541
return $this->skipStaticColumns;

app/code/Magento/Catalog/Model/Indexer/Category/Flat/Action/Rows.php

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -171,27 +171,30 @@ private function buildIndexData(Store $store, $categoriesIdsChunk, $attributesDa
171171
foreach ($categoriesIdsChunk as $categoryId) {
172172
try {
173173
$category = $this->categoryRepository->get($categoryId);
174-
$categoryData = $category->getData();
175-
$linkId = $categoryData[$linkField];
176-
177-
$categoryAttributesData = [];
178-
if (isset($attributesData[$linkId]) && is_array($attributesData[$linkId])) {
179-
$categoryAttributesData = $attributesData[$linkId];
180-
}
181-
$categoryIndexData = $this->buildCategoryIndexData(
182-
$store,
183-
$categoryData,
184-
$categoryAttributesData
185-
);
186-
$data[] = $categoryIndexData;
187174
} catch (NoSuchEntityException $e) {
188-
// ignore
175+
continue;
189176
}
177+
178+
$categoryData = $category->getData();
179+
$linkId = $categoryData[$linkField];
180+
181+
$categoryAttributesData = [];
182+
if (isset($attributesData[$linkId]) && is_array($attributesData[$linkId])) {
183+
$categoryAttributesData = $attributesData[$linkId];
184+
}
185+
$categoryIndexData = $this->buildCategoryIndexData(
186+
$store,
187+
$categoryData,
188+
$categoryAttributesData
189+
);
190+
$data[] = $categoryIndexData;
190191
}
191192
return $data;
192193
}
193194

194195
/**
196+
* Prepare Category data
197+
*
195198
* @param Store $store
196199
* @param array $categoryData
197200
* @param array $categoryAttributesData
@@ -214,7 +217,8 @@ private function buildCategoryIndexData(Store $store, array $categoryData, array
214217
* Insert or update index data
215218
*
216219
* @param string $tableName
217-
* @param $data
220+
* @param array $data
221+
* @return void
218222
*/
219223
private function updateIndexData($tableName, $data)
220224
{

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ abstract class AbstractAction
4242

4343
/**
4444
* Suffix for table to show it is temporary
45-
* @deprecated
45+
* @deprecated see getIndexTable
4646
*/
4747
const TEMPORARY_TABLE_SUFFIX = '_tmp';
4848

app/code/Magento/Catalog/Model/Indexer/Category/Product/Action/Full.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ protected function reindex(): void
174174
foreach ($this->storeManager->getStores() as $store) {
175175
if ($this->getPathFromCategoryId($store->getRootCategoryId())) {
176176
$userFunctions[$store->getId()] = function () use ($store) {
177-
return $this->reindexStore($store);
177+
$this->reindexStore($store);
178178
};
179179
}
180180
}

0 commit comments

Comments
 (0)