Code Duplication    Length = 23-25 lines in 3 locations

Components/Helper.php 3 locations

@@ 72-94 (lines=23) @@
69
     * @param int $mode
70
     * @return null|ProductModel
71
     */
72
    public function getArticleModelByProduct(Product $product, $mode = Query::HYDRATE_OBJECT)
73
    {
74
        $builder = $this->manager->createQueryBuilder();
75
        $builder->select(['ba', 'a']);
76
        $builder->from('Shopware\CustomModels\Connect\Attribute', 'ba');
77
        $builder->join('ba.article', 'a');
78
79
        $builder->where('ba.shopId = :shopId AND ba.sourceId = :sourceId');
80
        $query = $builder->getQuery();
81
82
        $query->setParameter('shopId', $product->shopId);
83
        $query->setParameter('sourceId', $product->sourceId);
84
        $result = $query->getResult(
85
            $mode
86
        );
87
88
        if (isset($result[0])) {
89
            $attribute = $result[0];
90
91
            return $attribute->getArticle();
92
        }
93
94
        return null;
95
    }
96
97
    /**
@@ 102-126 (lines=25) @@
99
     * @param int $mode
100
     * @return null|ProductDetail
101
     */
102
    public function getArticleDetailModelByProduct(Product $product, $mode = Query::HYDRATE_OBJECT)
103
    {
104
        $builder = $this->manager->createQueryBuilder();
105
        $builder->select(['ba', 'd']);
106
        $builder->from('Shopware\CustomModels\Connect\Attribute', 'ba');
107
        $builder->join('ba.articleDetail', 'd');
108
        $builder->leftJoin('d.attribute', 'at');
109
        $builder->where('ba.shopId = :shopId AND ba.sourceId = :sourceId');
110
111
        $query = $builder->getQuery();
112
        $query->setParameter('shopId', $product->shopId);
113
        $query->setParameter('sourceId', $product->sourceId);
114
115
        $result = $query->getResult(
116
            $mode
117
        );
118
119
        if (isset($result[0])) {
120
            /** @var \Shopware\CustomModels\Connect\Attribute $attribute */
121
            $attribute = $result[0];
122
123
            return $attribute->getArticleDetail();
124
        }
125
126
        return null;
127
    }
128
129
    public function getConnectArticleModel($sourceId, $shopId)
@@ 732-756 (lines=25) @@
729
     * @param int $mode
730
     * @return null|ProductModel
731
     */
732
    public function getArticleByRemoteProduct(Product $product, $mode = Query::HYDRATE_OBJECT)
733
    {
734
        $builder = $this->manager->createQueryBuilder();
735
        $builder->select(['ba', 'd']);
736
        $builder->from('Shopware\CustomModels\Connect\Attribute', 'ba');
737
        $builder->join('ba.articleDetail', 'd');
738
        $builder->leftJoin('d.attribute', 'at');
739
740
        $builder->where('ba.groupId = :groupId AND ba.isMainVariant = 1 AND ba.shopId = :shopId');
741
        $query = $builder->getQuery();
742
743
        $query->setParameter('groupId', $product->groupId);
744
        $query->setParameter('shopId', $product->shopId);
745
        $result = $query->getResult(
746
            $mode
747
        );
748
749
        if (isset($result[0])) {
750
            /** @var \Shopware\CustomModels\Connect\Attribute $attribute */
751
            $attribute = $result[0];
752
753
            return $attribute->getArticle();
754
        }
755
756
        return null;
757
    }
758
759
    /**