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