Code Duplication    Length = 24-26 lines in 3 locations

Components/Helper.php 3 locations

@@ 76-99 (lines=24) @@
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
@@ 106-131 (lines=26) @@
103
     * @param int $mode
104
     * @return null|ProductDetail
105
     */
106
    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
    public function getConnectArticleModel($sourceId, $shopId)
134
    {
@@ 691-715 (lines=25) @@
688
     * @param int $mode
689
     * @return null|ProductModel
690
     */
691
    public function getArticleByRemoteProduct(Product $product, $mode = Query::HYDRATE_OBJECT)
692
    {
693
        $builder = $this->manager->createQueryBuilder();
694
        $builder->select(['ba', 'd']);
695
        $builder->from('Shopware\CustomModels\Connect\Attribute', 'ba');
696
        $builder->join('ba.articleDetail', 'd');
697
        $builder->leftJoin('d.attribute', 'at');
698
699
        $builder->where('ba.groupId = :groupId AND ba.isMainVariant = 1 AND ba.shopId = :shopId');
700
        $query = $builder->getQuery();
701
702
        $query->setParameter('groupId', $product->groupId);
703
        $query->setParameter('shopId', $product->shopId);
704
        $result = $query->getResult(
705
            $mode
706
        );
707
708
        if (isset($result[0])) {
709
            /** @var \Shopware\CustomModels\Connect\Attribute $attribute */
710
            $attribute = $result[0];
711
712
            return $attribute->getArticle();
713
        }
714
715
        return null;
716
    }
717
718
    /**