Code Duplication    Length = 18-24 lines in 3 locations

src/Oro/Bundle/MagentoBundle/Entity/Repository/CartRepository.php 1 location

@@ 304-327 (lines=24) @@
301
     *
302
     * @return int
303
     */
304
    public function getCustomersCountWhatMakeCarts(AclHelper $aclHelper, \DateTime $from = null, \DateTime $to = null)
305
    {
306
        $qb = $this->createQueryBuilder('c');
307
308
        try {
309
            $qb
310
                ->select('COUNT(DISTINCT c.customer) + SUM(CASE WHEN c.isGuest = true THEN 1 ELSE 0 END)');
311
            if ($from) {
312
                $qb
313
                    ->andWhere('c.createdAt > :from')
314
                    ->setParameter('from', $from);
315
            }
316
            if ($to) {
317
                $qb
318
                    ->andWhere('c.createdAt < :to')
319
                    ->setParameter('to', $to);
320
            }
321
            $this->applyActiveChannelLimitation($qb);
322
323
            return (int)$aclHelper->apply($qb)->getSingleScalarResult();
324
        } catch (NoResultException $ex) {
325
            return 0;
326
        }
327
    }
328
329
    /**
330
     * @param string $alias

src/Oro/Bundle/MagentoBundle/Entity/Repository/OrderRepository.php 1 location

@@ 273-295 (lines=23) @@
270
     *
271
     * @return int
272
     */
273
    public function getUniqueBuyersCount(AclHelper $aclHelper, \DateTime $from = null, \DateTime $to = null)
274
    {
275
        $qb = $this->createQueryBuilder('o');
276
277
        try {
278
            $qb->select('COUNT(DISTINCT o.customer) + SUM(CASE WHEN o.isGuest = true THEN 1 ELSE 0 END)');
279
            if ($from) {
280
                $qb
281
                    ->andWhere('o.createdAt > :from')
282
                    ->setParameter('from', $from);
283
            }
284
            if ($to) {
285
                $qb
286
                    ->andWhere('o.createdAt > :to')
287
                    ->setParameter('to', $to);
288
            }
289
            $this->applyActiveChannelLimitation($qb);
290
291
            return (int) $aclHelper->apply($qb)->getSingleScalarResult();
292
        } catch (NoResultException $ex) {
293
            return 0;
294
        }
295
    }
296
297
    /**
298
     * @param $alias

src/Oro/Bundle/SalesBundle/Entity/Repository/OpportunityRepository.php 1 location

@@ 491-508 (lines=18) @@
488
     *
489
     * @return double
490
     */
491
    public function getWeightedPipelineAmount(AclHelper $aclHelper, \DateTime $start = null, \DateTime $end = null)
492
    {
493
        $qb = $this->createQueryBuilder('o');
494
495
        $qb->select('SUM(o.budgetAmount * o.probability)');
496
        if ($start) {
497
            $qb
498
                ->andWhere('o.createdAt > :start')
499
                ->setParameter('start', $start);
500
        }
501
        if ($end) {
502
            $qb
503
                ->andWhere('o.createdAt < :end')
504
                ->setParameter('end', $end);
505
        }
506
507
        return $aclHelper->apply($qb)->getSingleScalarResult();
508
    }
509
510
    /**
511
     * @param AclHelper $aclHelper