Code Duplication    Length = 13-17 lines in 2 locations

src/OroCRM/Bundle/MagentoBundle/Entity/Repository/OrderRepository.php 2 locations

@@ 25-41 (lines=17) @@
22
     * @param AclHelper $aclHelper
23
     * @return int
24
     */
25
    public function getRevenueValueByPeriod(\DateTime $start, \DateTime $end, AclHelper $aclHelper)
26
    {
27
        $select = 'SUM(
28
             CASE WHEN orders.subtotalAmount IS NOT NULL THEN orders.subtotalAmount ELSE 0 END -
29
             CASE WHEN orders.discountAmount IS NOT NULL THEN ABS(orders.discountAmount) ELSE 0 END
30
             ) as val';
31
        $qb    = $this->createQueryBuilder('orders');
32
        $qb->select($select)
33
            ->andWhere($qb->expr()->between('orders.createdAt', ':dateStart', ':dateEnd'))
34
            ->setParameter('dateStart', $start)
35
            ->setParameter('dateEnd', $end);
36
        $this->applyActiveChannelLimitation($qb);
37
38
        $value = $aclHelper->apply($qb)->getOneOrNullResult();
39
40
        return $value['val'] ? : 0;
41
    }
42
43
    /**
44
     * @param \DateTime $start
@@ 49-61 (lines=13) @@
46
     * @param AclHelper $aclHelper
47
     * @return int
48
     */
49
    public function getOrdersNumberValueByPeriod(\DateTime $start, \DateTime $end, AclHelper $aclHelper)
50
    {
51
        $qb    = $this->createQueryBuilder('o');
52
        $qb->select('count(o.id) as val')
53
            ->andWhere($qb->expr()->between('o.createdAt', ':dateStart', ':dateEnd'))
54
            ->setParameter('dateStart', $start)
55
            ->setParameter('dateEnd', $end);
56
        $this->applyActiveChannelLimitation($qb);
57
58
        $value = $aclHelper->apply($qb)->getOneOrNullResult();
59
60
        return $value['val'] ? : 0;
61
    }
62
63
    /**
64
     * get Average Order Amount by given period