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
    /**
134
     * Get article detail by his number
@@ 724-748 (lines=25) @@
721
     * @param int $mode
722
     * @return null|ProductModel
723
     */
724
    public function getArticleByRemoteProduct(Product $product, $mode = Query::HYDRATE_OBJECT)
725
    {
726
        $builder = $this->manager->createQueryBuilder();
727
        $builder->select(['ba', 'd']);
728
        $builder->from('Shopware\CustomModels\Connect\Attribute', 'ba');
729
        $builder->join('ba.articleDetail', 'd');
730
        $builder->leftJoin('d.attribute', 'at');
731
732
        $builder->where('ba.groupId = :groupId AND ba.isMainVariant = 1 AND ba.shopId = :shopId');
733
        $query = $builder->getQuery();
734
735
        $query->setParameter('groupId', $product->groupId);
736
        $query->setParameter('shopId', $product->shopId);
737
        $result = $query->getResult(
738
            $mode
739
        );
740
741
        if (isset($result[0])) {
742
            /** @var \Shopware\CustomModels\Connect\Attribute $attribute */
743
            $attribute = $result[0];
744
745
            return $attribute->getArticle();
746
        }
747
748
        return null;
749
    }
750
751
    /**