Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like Helper often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Helper, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 27 | class Helper |
||
| 28 | { |
||
| 29 | /** |
||
| 30 | * @var ModelManager |
||
| 31 | */ |
||
| 32 | private $manager; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @var CategoryQuery |
||
| 36 | */ |
||
| 37 | private $connectCategoryQuery; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * @var ProductQuery |
||
| 41 | */ |
||
| 42 | private $connectProductQuery; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @param ModelManager $manager |
||
| 46 | * @param CategoryQuery |
||
| 47 | * @param ProductQuery |
||
| 48 | */ |
||
| 49 | public function __construct( |
||
| 50 | ModelManager $manager, |
||
| 51 | CategoryQuery $connectCategoryQuery, |
||
| 52 | ProductQuery $connectProductQuery |
||
| 53 | ) { |
||
| 54 | $this->manager = $manager; |
||
| 55 | $this->connectCategoryQuery = $connectCategoryQuery; |
||
| 56 | $this->connectProductQuery = $connectProductQuery; |
||
| 57 | } |
||
| 58 | |||
| 59 | /** |
||
| 60 | * @return Group |
||
| 61 | */ |
||
| 62 | public function getDefaultCustomerGroup() |
||
| 63 | { |
||
| 64 | $repository = $this->manager->getRepository('Shopware\Models\Customer\Group'); |
||
| 65 | |||
| 66 | return $repository->findOneBy(['key' => 'EK']); |
||
| 67 | } |
||
| 68 | |||
| 69 | /** |
||
| 70 | * Returns an article model for a given (sdk) product. |
||
| 71 | * |
||
| 72 | * @param Product $product |
||
| 73 | * @param int $mode |
||
| 74 | * @return null|ProductModel |
||
| 75 | */ |
||
| 76 | public function getArticleModelByProduct(Product $product, $mode = Query::HYDRATE_OBJECT) |
||
| 77 | { |
||
| 78 | $builder = $this->manager->createQueryBuilder(); |
||
| 79 | $builder->select(['ba', 'a']); |
||
| 80 | $builder->from('Shopware\CustomModels\Connect\Attribute', 'ba'); |
||
| 81 | $builder->join('ba.article', 'a'); |
||
| 82 | |||
| 83 | $builder->where('ba.shopId = :shopId AND ba.sourceId = :sourceId'); |
||
| 84 | $query = $builder->getQuery(); |
||
| 85 | |||
| 86 | $query->setParameter('shopId', $product->shopId); |
||
| 87 | $query->setParameter('sourceId', (string) $product->sourceId); |
||
| 88 | $result = $query->getResult( |
||
| 89 | $mode |
||
| 90 | ); |
||
| 91 | |||
| 92 | if (isset($result[0])) { |
||
| 93 | $attribute = $result[0]; |
||
| 94 | |||
| 95 | return $attribute->getArticle(); |
||
| 96 | } |
||
| 97 | |||
| 98 | return null; |
||
| 99 | } |
||
| 100 | |||
| 101 | /** |
||
| 102 | * @param Product $product |
||
| 103 | * @param int $mode |
||
| 104 | * @return null|ProductDetail |
||
| 105 | */ |
||
| 106 | View Code Duplication | public function getArticleDetailModelByProduct(Product $product, $mode = Query::HYDRATE_OBJECT) |
|
|
|
|||
| 107 | { |
||
| 108 | $builder = $this->manager->createQueryBuilder(); |
||
| 109 | $builder->select(['ba', 'd']); |
||
| 110 | $builder->from('Shopware\CustomModels\Connect\Attribute', 'ba'); |
||
| 111 | $builder->join('ba.articleDetail', 'd'); |
||
| 112 | $builder->leftJoin('d.attribute', 'at'); |
||
| 113 | $builder->where('ba.shopId = :shopId AND ba.sourceId = :sourceId'); |
||
| 114 | |||
| 115 | $query = $builder->getQuery(); |
||
| 116 | $query->setParameter('shopId', $product->shopId); |
||
| 117 | $query->setParameter('sourceId', (string) $product->sourceId); |
||
| 118 | |||
| 119 | $result = $query->getResult( |
||
| 120 | $mode |
||
| 121 | ); |
||
| 122 | |||
| 123 | if (isset($result[0])) { |
||
| 124 | /** @var \Shopware\CustomModels\Connect\Attribute $attribute */ |
||
| 125 | $attribute = $result[0]; |
||
| 126 | |||
| 127 | return $attribute->getArticleDetail(); |
||
| 128 | } |
||
| 129 | |||
| 130 | return null; |
||
| 131 | } |
||
| 132 | |||
| 133 | /** |
||
| 134 | * Get article detail by his number |
||
| 135 | * |
||
| 136 | * @param string $number |
||
| 137 | * @return null|ProductDetail |
||
| 138 | */ |
||
| 139 | public function getDetailByNumber($number) |
||
| 140 | { |
||
| 141 | return $this->manager->getRepository(ProductDetail::class)->findOneBy(['number' => $number]); |
||
| 142 | } |
||
| 143 | |||
| 144 | public function getConnectArticleModel($sourceId, $shopId) |
||
| 145 | { |
||
| 146 | $builder = $this->manager->createQueryBuilder(); |
||
| 147 | $builder->select(['ba', 'a']); |
||
| 148 | $builder->from('Shopware\CustomModels\Connect\Attribute', 'ba'); |
||
| 149 | $builder->join('ba.article', 'a'); |
||
| 150 | $builder->join('a.mainDetail', 'd'); |
||
| 151 | $builder->leftJoin('d.attribute', 'at'); |
||
| 152 | |||
| 153 | $builder->where('ba.shopId = :shopId AND ba.sourceId = :sourceId'); |
||
| 154 | $query = $builder->getQuery(); |
||
| 155 | |||
| 156 | $query->setParameter('shopId', $shopId); |
||
| 157 | $query->setParameter('sourceId', (string) $sourceId); |
||
| 158 | $result = $query->getResult( |
||
| 159 | $query::HYDRATE_OBJECT |
||
| 160 | ); |
||
| 161 | |||
| 162 | if (isset($result[0])) { |
||
| 163 | $attribute = $result[0]; |
||
| 164 | |||
| 165 | return $attribute->getArticle(); |
||
| 166 | } |
||
| 167 | |||
| 168 | return null; |
||
| 169 | } |
||
| 170 | |||
| 171 | /** |
||
| 172 | * @param array $orderNumbers |
||
| 173 | * @return array |
||
| 174 | */ |
||
| 175 | View Code Duplication | public function getArticleIdsByNumber(array $orderNumbers) |
|
| 176 | { |
||
| 177 | $builder = $this->manager->getConnection()->createQueryBuilder(); |
||
| 178 | |||
| 179 | $rows = $builder->select('d.articleID as articleId') |
||
| 180 | ->from('s_articles_details', 'd') |
||
| 181 | ->where('d.ordernumber IN (:orderNumbers)') |
||
| 182 | ->setParameter('orderNumbers', $orderNumbers, \Doctrine\DBAL\Connection::PARAM_STR_ARRAY) |
||
| 183 | ->execute() |
||
| 184 | ->fetchAll(); |
||
| 185 | |||
| 186 | return array_map(function ($row) { |
||
| 187 | return $row['articleId']; |
||
| 188 | }, $rows); |
||
| 189 | } |
||
| 190 | |||
| 191 | /** |
||
| 192 | * Returns article detail model by |
||
| 193 | * given sourceId and shopId |
||
| 194 | * |
||
| 195 | * @param string $sourceId |
||
| 196 | * @param int $shopId |
||
| 197 | * @return null|ProductDetail |
||
| 198 | */ |
||
| 199 | public function getConnectArticleDetailModel($sourceId, $shopId) |
||
| 200 | { |
||
| 201 | $product = new Product(['sourceId' => $sourceId, 'shopId' => $shopId]); |
||
| 202 | |||
| 203 | return $this->getArticleDetailModelByProduct($product); |
||
| 204 | } |
||
| 205 | |||
| 206 | /** |
||
| 207 | * Helper to update the connect_items table |
||
| 208 | */ |
||
| 209 | public function updateConnectProducts() |
||
| 210 | { |
||
| 211 | // Insert new articles |
||
| 212 | $sql = " |
||
| 213 | INSERT INTO `s_plugin_connect_items` (article_id, article_detail_id, source_id) |
||
| 214 | SELECT a.id, ad.id, IF(ad.kind = 1, a.id, CONCAT(a.id, '-', ad.id)) as sourceID |
||
| 215 | |||
| 216 | FROM s_articles a |
||
| 217 | |||
| 218 | LEFT JOIN `s_articles_details` ad |
||
| 219 | ON a.id = ad.articleId |
||
| 220 | |||
| 221 | LEFT JOIN `s_plugin_connect_items` bi |
||
| 222 | ON bi.article_detail_id = ad.id |
||
| 223 | |||
| 224 | |||
| 225 | WHERE a.id IS NOT NULL |
||
| 226 | AND ad.id IS NOT NULL |
||
| 227 | AND bi.id IS NULL |
||
| 228 | "; |
||
| 229 | |||
| 230 | $this->manager->getConnection()->exec($sql); |
||
| 231 | |||
| 232 | // Delete removed articles from s_plugin_connect_items |
||
| 233 | $sql = ' |
||
| 234 | DELETE bi FROM `s_plugin_connect_items` bi |
||
| 235 | |||
| 236 | LEFT JOIN `s_articles_details` ad |
||
| 237 | ON ad.id = bi.article_detail_id |
||
| 238 | |||
| 239 | WHERE ad.id IS NULL |
||
| 240 | '; |
||
| 241 | |||
| 242 | $this->manager->getConnection()->exec($sql); |
||
| 243 | } |
||
| 244 | |||
| 245 | /** |
||
| 246 | * Returns wether connect categories have to be recreated or not |
||
| 247 | * @return bool |
||
| 248 | */ |
||
| 249 | public function checkIfConnectCategoriesHaveToBeRecreated() |
||
| 250 | { |
||
| 251 | $configComponent = ConfigFactory::getConfigInstance(); |
||
| 252 | $result = $configComponent->getConfig('recreateConnectCategories'); |
||
| 253 | if ($result === 0) { |
||
| 254 | return true; |
||
| 255 | } |
||
| 256 | |||
| 257 | return false; |
||
| 258 | } |
||
| 259 | |||
| 260 | /** |
||
| 261 | * Returns a remote connectProduct e.g. for checkout maniputlations |
||
| 262 | * |
||
| 263 | * @param array $ids |
||
| 264 | * @param int $shopId |
||
| 265 | * @return array |
||
| 266 | */ |
||
| 267 | public function getRemoteProducts(array $ids, $shopId) |
||
| 268 | { |
||
| 269 | return $this->connectProductQuery->getRemote($ids, $shopId); |
||
| 270 | } |
||
| 271 | |||
| 272 | /** |
||
| 273 | * Returns a local connectProduct for export |
||
| 274 | * |
||
| 275 | * @param array $sourceIds |
||
| 276 | * @return Product[] |
||
| 277 | */ |
||
| 278 | public function getLocalProduct(array $sourceIds) |
||
| 279 | { |
||
| 280 | return $this->connectProductQuery->getLocal($sourceIds); |
||
| 281 | } |
||
| 282 | |||
| 283 | /** |
||
| 284 | * Does the current basket contain connect products? |
||
| 285 | * |
||
| 286 | * @param $session |
||
| 287 | * @return bool |
||
| 288 | */ |
||
| 289 | public function hasBasketConnectProducts($session, $userId = null) |
||
| 290 | { |
||
| 291 | $connection = $this->manager->getConnection(); |
||
| 292 | $sql = 'SELECT ob.articleID |
||
| 293 | |||
| 294 | FROM s_order_basket ob |
||
| 295 | |||
| 296 | INNER JOIN s_plugin_connect_items bi |
||
| 297 | ON bi.article_id = ob.articleID |
||
| 298 | AND bi.shop_id IS NOT NULL |
||
| 299 | |||
| 300 | WHERE ob.sessionID=? |
||
| 301 | '; |
||
| 302 | $whereClause = [$session]; |
||
| 303 | |||
| 304 | if ($userId > 0) { |
||
| 305 | $sql .= ' OR userID=?'; |
||
| 306 | $whereClause[] = $userId; |
||
| 307 | } |
||
| 308 | |||
| 309 | $sql .= ' LIMIT 1'; |
||
| 310 | |||
| 311 | $result = $connection->fetchArray($sql, $whereClause); |
||
| 312 | |||
| 313 | return !empty($result); |
||
| 314 | } |
||
| 315 | |||
| 316 | /** |
||
| 317 | * Will return the connectAttribute for a given model. The model can be an Article\Article or Article\Detail |
||
| 318 | * |
||
| 319 | * @param $model ProductModel|ProductDetail |
||
| 320 | * @return ConnectAttribute |
||
| 321 | */ |
||
| 322 | public function getConnectAttributeByModel($model) |
||
| 323 | { |
||
| 324 | if (!$model->getId()) { |
||
| 325 | return false; |
||
| 326 | } |
||
| 327 | $repository = $this->manager->getRepository('Shopware\CustomModels\Connect\Attribute'); |
||
| 328 | |||
| 329 | if ($model instanceof ProductModel) { |
||
| 330 | if (!$model->getMainDetail()) { |
||
| 331 | return false; |
||
| 332 | } |
||
| 333 | |||
| 334 | return $repository->findOneBy(['articleDetailId' => $model->getMainDetail()->getId()]); |
||
| 335 | } elseif ($model instanceof ProductDetail) { |
||
| 336 | return $repository->findOneBy(['articleDetailId' => $model->getId()]); |
||
| 337 | } |
||
| 338 | |||
| 339 | return false; |
||
| 340 | } |
||
| 341 | |||
| 342 | /** |
||
| 343 | * Returns connectAttributes for all article details by given article object |
||
| 344 | * |
||
| 345 | * @param ProductModel $article |
||
| 346 | * @return \Shopware\CustomModels\Connect\Attribute[] |
||
| 347 | */ |
||
| 348 | public function getConnectAttributesByArticle(ProductModel $article) |
||
| 349 | { |
||
| 350 | $builder = $this->manager->createQueryBuilder(); |
||
| 351 | $builder->select(['connectAttribute', 'detail']); |
||
| 352 | $builder->from('Shopware\CustomModels\Connect\Attribute', 'connectAttribute'); |
||
| 353 | $builder->innerJoin('connectAttribute.articleDetail', 'detail'); |
||
| 354 | |||
| 355 | $builder->where('connectAttribute.articleId = :articleId'); |
||
| 356 | $query = $builder->getQuery(); |
||
| 357 | |||
| 358 | $query->setParameter('articleId', $article->getId()); |
||
| 359 | |||
| 360 | return $query->getResult(); |
||
| 361 | } |
||
| 362 | |||
| 363 | /** |
||
| 364 | * Returns true when product is exported to Connect |
||
| 365 | * |
||
| 366 | * @param Attribute $connectAttribute |
||
| 367 | * @return bool |
||
| 368 | */ |
||
| 369 | public function isProductExported(Attribute $connectAttribute) |
||
| 370 | { |
||
| 371 | $status = $connectAttribute->getExportStatus(); |
||
| 372 | if ($connectAttribute->isExported()) { |
||
| 373 | return true; |
||
| 374 | } |
||
| 375 | |||
| 376 | if ($status == Attribute::STATUS_INSERT) { |
||
| 377 | return true; |
||
| 378 | } |
||
| 379 | |||
| 380 | if ($status == Attribute::STATUS_UPDATE) { |
||
| 381 | return true; |
||
| 382 | } |
||
| 383 | |||
| 384 | if ($status == Attribute::STATUS_SYNCED) { |
||
| 385 | return true; |
||
| 386 | } |
||
| 387 | |||
| 388 | return false; |
||
| 389 | } |
||
| 390 | |||
| 391 | /** |
||
| 392 | * Verifies that at least one variant from |
||
| 393 | * same article is exported. |
||
| 394 | * |
||
| 395 | * @param Attribute $connectAttribute |
||
| 396 | * @return bool |
||
| 397 | */ |
||
| 398 | public function hasExportedVariants(Attribute $connectAttribute) |
||
| 399 | { |
||
| 400 | $builder = $this->manager->getConnection()->createQueryBuilder(); |
||
| 401 | $builder->select('COUNT(spci.id)') |
||
| 402 | ->from('s_plugin_connect_items', 'spci') |
||
| 403 | ->where('spci.article_id = :articleId AND spci.export_status IN (:exportStatus) AND spci.shop_id IS NULL') |
||
| 404 | ->setParameter('articleId', $connectAttribute->getArticleId(), \PDO::PARAM_INT) |
||
| 405 | ->setParameter( |
||
| 406 | ':exportStatus', |
||
| 407 | [Attribute::STATUS_INSERT, Attribute::STATUS_UPDATE, Attribute::STATUS_SYNCED], |
||
| 408 | \Doctrine\DBAL\Connection::PARAM_STR_ARRAY |
||
| 409 | ); |
||
| 410 | |||
| 411 | return $builder->execute()->fetchColumn() > 0; |
||
| 412 | } |
||
| 413 | |||
| 414 | /** |
||
| 415 | * Helper method to create a connect attribute on the fly |
||
| 416 | * |
||
| 417 | * @param $model |
||
| 418 | * @throws \RuntimeException |
||
| 419 | * @return ConnectAttribute |
||
| 420 | */ |
||
| 421 | public function getOrCreateConnectAttributeByModel($model) |
||
| 422 | { |
||
| 423 | $attribute = $this->getConnectAttributeByModel($model); |
||
| 424 | |||
| 425 | if (!$attribute) { |
||
| 426 | $attribute = new ConnectAttribute(); |
||
| 427 | $attribute->setPurchasePriceHash(''); |
||
| 428 | $attribute->setOfferValidUntil(''); |
||
| 429 | $attribute->setStream(''); |
||
| 430 | |||
| 431 | if ($model instanceof ProductModel) { |
||
| 432 | $attribute->setArticle($model); |
||
| 433 | $attribute->setArticleDetail($model->getMainDetail()); |
||
| 434 | $attribute->setSourceId( |
||
| 435 | $this->generateSourceId($model->getMainDetail()) |
||
| 436 | ); |
||
| 437 | } elseif ($model instanceof ProductDetail) { |
||
| 438 | $attribute->setArticle($model->getArticle()); |
||
| 439 | $attribute->setArticleDetail($model); |
||
| 440 | $attribute->setSourceId( |
||
| 441 | $this->generateSourceId($model) |
||
| 442 | ); |
||
| 443 | } else { |
||
| 444 | throw new \RuntimeException('Passed model needs to be an article or an article detail'); |
||
| 445 | } |
||
| 446 | $this->manager->persist($attribute); |
||
| 447 | $this->manager->flush($attribute); |
||
| 448 | } |
||
| 449 | |||
| 450 | return $attribute; |
||
| 451 | } |
||
| 452 | |||
| 453 | /** |
||
| 454 | * Returns connect attributes for article |
||
| 455 | * and all variants. |
||
| 456 | * If connect attribute does not exist |
||
| 457 | * it will be created. |
||
| 458 | * |
||
| 459 | * @param ProductModel $article |
||
| 460 | * @return array |
||
| 461 | */ |
||
| 462 | public function getOrCreateConnectAttributes(ProductModel $article) |
||
| 463 | { |
||
| 464 | $attributes = []; |
||
| 465 | /** @var \Shopware\Models\Article\Detail $detail */ |
||
| 466 | foreach ($article->getDetails() as $detail) { |
||
| 467 | $attributes[] = $this->getOrCreateConnectAttributeByModel($detail); |
||
| 468 | } |
||
| 469 | |||
| 470 | return $attributes; |
||
| 471 | } |
||
| 472 | |||
| 473 | /** |
||
| 474 | * Generate sourceId |
||
| 475 | * |
||
| 476 | * @param ProductDetail $detail |
||
| 477 | * @return string |
||
| 478 | */ |
||
| 479 | public function generateSourceId(ProductDetail $detail) |
||
| 480 | { |
||
| 481 | if ($detail->getKind() == 1) { |
||
| 482 | $sourceId = (string) $detail->getArticle()->getId(); |
||
| 483 | } else { |
||
| 484 | $sourceId = sprintf( |
||
| 485 | '%s-%s', |
||
| 486 | $detail->getArticle()->getId(), |
||
| 487 | $detail->getId() |
||
| 488 | ); |
||
| 489 | } |
||
| 490 | |||
| 491 | return $sourceId; |
||
| 492 | } |
||
| 493 | |||
| 494 | /** |
||
| 495 | * @param $id |
||
| 496 | * @return array |
||
| 497 | */ |
||
| 498 | public function getConnectCategoryForProduct($id) |
||
| 499 | { |
||
| 500 | return $this->connectCategoryQuery->getConnectCategoryForProduct($id); |
||
| 501 | } |
||
| 502 | |||
| 503 | public function getMostRelevantConnectCategory($categories) |
||
| 515 | |||
| 516 | /** |
||
| 517 | * Defines the update flags |
||
| 518 | * |
||
| 519 | * @return array |
||
| 520 | */ |
||
| 521 | public function getUpdateFlags() |
||
| 525 | |||
| 526 | /** |
||
| 527 | * Returns shopware unit entity |
||
| 528 | * |
||
| 529 | * @param $unitKey |
||
| 530 | * @return \Shopware\Models\Article\Unit |
||
| 531 | */ |
||
| 532 | public function getUnit($unitKey) |
||
| 533 | { |
||
| 534 | $repository = $this->manager->getRepository('Shopware\Models\Article\Unit'); |
||
| 535 | |||
| 536 | return $repository->findOneBy(['unit' => $unitKey]); |
||
| 537 | } |
||
| 538 | |||
| 539 | /** |
||
| 540 | * Clear article cache |
||
| 541 | */ |
||
| 542 | public function clearArticleCache($articleId) |
||
| 543 | { |
||
| 544 | Shopware()->Events()->notify( |
||
| 545 | 'Shopware_Plugins_HttpCache_InvalidateCacheId', |
||
| 546 | ['cacheId' => 'a' . $articleId] |
||
| 549 | |||
| 550 | /** |
||
| 551 | * Replace unit and ref quantity |
||
| 552 | * @param $products |
||
| 553 | * @return mixed |
||
| 554 | */ |
||
| 555 | public function prepareConnectUnit($products) |
||
| 579 | |||
| 580 | /** |
||
| 581 | * Removes connect reservation from session |
||
| 582 | */ |
||
| 583 | public function clearConnectReservation() |
||
| 587 | |||
| 588 | /** |
||
| 589 | * Collect sourceIds by given article ids |
||
| 590 | * |
||
| 591 | * @param array $articleIds |
||
| 592 | * @return array |
||
| 593 | */ |
||
| 594 | public function getArticleSourceIds(array $articleIds) |
||
| 608 | |||
| 609 | /** |
||
| 610 | * Get ShopProductId struct by given article detail id |
||
| 611 | * It contains product sourceId and shopId. |
||
| 612 | * If $articleDetailId is local product, $shopProductId->shopId will be null. |
||
| 613 | * |
||
| 614 | * @param int $articleDetailId |
||
| 615 | * @return ShopProductId |
||
| 616 | */ |
||
| 617 | public function getShopProductId($articleDetailId) |
||
| 630 | |||
| 631 | /** |
||
| 632 | * Check if given articleDetailId is remote product |
||
| 633 | * |
||
| 634 | * @param int $articleDetailId |
||
| 635 | * @return bool |
||
| 636 | */ |
||
| 637 | public function isRemoteArticleDetail($articleDetailId) |
||
| 654 | |||
| 655 | /** |
||
| 656 | * Check if given articleDetailId is remote product |
||
| 657 | * |
||
| 658 | * @param int $articleDetailId |
||
| 659 | * @return bool |
||
| 660 | */ |
||
| 661 | public function isRemoteArticleDetailDBAL($articleDetailId) |
||
| 672 | |||
| 673 | /** |
||
| 674 | * Extract article ID and detail ID |
||
| 675 | * from source ID |
||
| 676 | * |
||
| 677 | * @param $sourceId |
||
| 678 | * @return array |
||
| 679 | */ |
||
| 680 | public function explodeArticleId($sourceId) |
||
| 692 | |||
| 693 | /** |
||
| 694 | * Creates Shopware product model |
||
| 695 | * |
||
| 696 | * @param Product $product |
||
| 697 | * @return ProductModel |
||
| 698 | */ |
||
| 699 | public function createProductModel(Product $product) |
||
| 709 | |||
| 710 | /** |
||
| 711 | * Returns main article detail by given groupId |
||
| 712 | * |
||
| 713 | * @param $product |
||
| 714 | * @param int $mode |
||
| 715 | * @return null|ProductModel |
||
| 716 | */ |
||
| 717 | View Code Duplication | public function getArticleByRemoteProduct(Product $product, $mode = Query::HYDRATE_OBJECT) |
|
| 743 | |||
| 744 | /** |
||
| 745 | * @param int $articleId |
||
| 746 | * @return array |
||
| 747 | */ |
||
| 748 | public function getSourceIdsFromArticleId($articleId) |
||
| 759 | |||
| 760 | /** |
||
| 761 | * @param Unit $localUnit |
||
| 762 | * @param string $remoteUnit |
||
| 763 | */ |
||
| 764 | public function updateUnitInRelatedProducts(Unit $localUnit, $remoteUnit) |
||
| 776 | |||
| 777 | /** |
||
| 778 | * Checks whether given sourceId is main variant. |
||
| 779 | * Works only with local products. |
||
| 780 | * SourceIds pattern is articleId-variantId (58-142) |
||
| 781 | * |
||
| 782 | * For remote product check is_main_variant flag in |
||
| 783 | * s_plugin_connect_items |
||
| 784 | * |
||
| 785 | * @param string $sourceId |
||
| 786 | * @return bool |
||
| 787 | */ |
||
| 788 | public function isMainVariant($sourceId) |
||
| 804 | |||
| 805 | public function getLocalArticleCount() |
||
| 809 | |||
| 810 | /** |
||
| 811 | * Recreates ConnectCategories wit the specified offset and batchsize |
||
| 812 | * @param int $offset |
||
| 813 | * @param int $batchsize |
||
| 814 | */ |
||
| 815 | public function recreateConnectCategories($offset, $batchsize) |
||
| 857 | |||
| 858 | /** |
||
| 859 | * @return int |
||
| 860 | */ |
||
| 861 | public function getProductCountForCategoryRecovery() |
||
| 869 | } |
||
| 870 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.