Code Duplication    Length = 24-26 lines in 3 locations

Components/Helper.php 3 locations

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