66
77namespace 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 ;
913use 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 */
1425class 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 ) {
@@ -414,7 +424,8 @@ private function getLinkIds(array $entityIds)
414424 [$ linkField ]
415425 )->where (
416426 'e.entity_id IN (?) ' ,
417- $ entityIds
427+ $ entityIds ,
428+ \Zend_Db::INT_TYPE
418429 );
419430
420431 return $ this ->connection ->fetchCol ($ select );
@@ -459,10 +470,12 @@ protected function getAttributeTypeValues($type, $entityIds, $storeId)
459470 ]
460471 )->where (
461472 "e.entity_id IN (?) " ,
462- $ entityIds
473+ $ entityIds ,
474+ \Zend_Db::INT_TYPE
463475 )->where (
464476 'def.store_id IN (?) ' ,
465- [\Magento \Store \Model \Store::DEFAULT_STORE_ID , $ storeId ]
477+ [Store::DEFAULT_STORE_ID , $ storeId ],
478+ \Zend_Db::INT_TYPE
466479 );
467480
468481 return $ this ->connection ->fetchAll ($ select );
@@ -501,14 +514,14 @@ protected function getTableName($name)
501514 /**
502515 * Get category metadata instance.
503516 *
504- * @return \Magento\Framework\EntityManager\ EntityMetadata
517+ * @return EntityMetadata
505518 */
506519 private function getCategoryMetadata ()
507520 {
508521 if (null === $ this ->categoryMetadata ) {
509- $ metadataPool = \ Magento \ Framework \ App \ ObjectManager::getInstance ()
522+ $ metadataPool = ObjectManager::getInstance ()
510523 ->get (\Magento \Framework \EntityManager \MetadataPool::class);
511- $ this ->categoryMetadata = $ metadataPool ->getMetadata (\ Magento \ Catalog \ Api \ Data \ CategoryInterface::class);
524+ $ this ->categoryMetadata = $ metadataPool ->getMetadata (CategoryInterface::class);
512525 }
513526 return $ this ->categoryMetadata ;
514527 }
@@ -521,8 +534,8 @@ private function getCategoryMetadata()
521534 private function getSkipStaticColumns ()
522535 {
523536 if (null === $ this ->skipStaticColumns ) {
524- $ provider = \ Magento \ Framework \ App \ ObjectManager::getInstance ()
525- ->get (\ Magento \ Catalog \ Model \ Indexer \ Category \ Flat \ SkipStaticColumnsProvider::class);
537+ $ provider = ObjectManager::getInstance ()
538+ ->get (SkipStaticColumnsProvider::class);
526539 $ this ->skipStaticColumns = $ provider ->get ();
527540 }
528541 return $ this ->skipStaticColumns ;
0 commit comments