Code Duplication    Length = 32-34 lines in 2 locations

src/Xtools/EditCounterRepository.php 2 locations

@@ 507-540 (lines=34) @@
504
     * @param User $user The user.
505
     * @return string[]
506
     */
507
    public function getMonthCounts(Project $project, User $user)
508
    {
509
        $username = $user->getUsername();
510
        $cacheKey = "monthcounts.$username";
511
        $this->stopwatch->start($cacheKey, 'XTools');
512
        if ($this->cache->hasItem($cacheKey)) {
513
            return $this->cache->getItem($cacheKey)->get();
514
        }
515
516
        $revisionTable = $this->getTableName($project->getDatabaseName(), 'revision');
517
        $pageTable = $this->getTableName($project->getDatabaseName(), 'page');
518
        $sql =
519
            "SELECT "
520
            . "     YEAR(rev_timestamp) AS `year`,"
521
            . "     MONTH(rev_timestamp) AS `month`,"
522
            . "     page_namespace,"
523
            . "     COUNT(rev_id) AS `count` "
524
            .  " FROM $revisionTable JOIN $pageTable ON (rev_page = page_id)"
525
            . " WHERE rev_user_text = :username"
526
            . " GROUP BY YEAR(rev_timestamp), MONTH(rev_timestamp), page_namespace "
527
            . " ORDER BY rev_timestamp DESC";
528
        $resultQuery = $this->getProjectsConnection()->prepare($sql);
529
        $resultQuery->bindParam(":username", $username);
530
        $resultQuery->execute();
531
        $totals = $resultQuery->fetchAll();
532
        
533
        $cacheItem = $this->cache->getItem($cacheKey);
534
        $cacheItem->expiresAfter(new DateInterval('PT10M'));
535
        $cacheItem->set($totals);
536
        $this->cache->save($cacheItem);
537
538
        $this->stopwatch->stop($cacheKey);
539
        return $totals;
540
    }
541
542
    /**
543
     * Get yearly edit totals for this user, grouped by namespace.
@@ 548-579 (lines=32) @@
545
     * @param User $user The user.
546
     * @return string[] ['<namespace>' => ['<year>' => 'total', ... ], ... ]
547
     */
548
    public function getYearCounts(Project $project, User $user)
549
    {
550
        $username = $user->getUsername();
551
        $cacheKey = "yearcounts.$username";
552
        $this->stopwatch->start($cacheKey, 'XTools');
553
        if ($this->cache->hasItem($cacheKey)) {
554
            return $this->cache->getItem($cacheKey)->get();
555
        }
556
557
        $revisionTable = $this->getTableName($project->getDatabaseName(), 'revision');
558
        $pageTable = $this->getTableName($project->getDatabaseName(), 'page');
559
        $sql = "SELECT "
560
            . "     YEAR(rev_timestamp) AS `year`,"
561
            . "     page_namespace,"
562
            . "     COUNT(rev_id) AS `count` "
563
            . " FROM $revisionTable JOIN $pageTable ON (rev_page = page_id)"
564
            . " WHERE rev_user_text = :username"
565
            . " GROUP BY YEAR(rev_timestamp), page_namespace "
566
            . " ORDER BY rev_timestamp DESC ";
567
        $resultQuery = $this->getProjectsConnection()->prepare($sql);
568
        $resultQuery->bindParam(":username", $username);
569
        $resultQuery->execute();
570
        $totals = $resultQuery->fetchAll();
571
572
        $cacheItem = $this->cache->getItem($cacheKey);
573
        $cacheItem->set($totals);
574
        $cacheItem->expiresAfter(new DateInterval('P10M'));
575
        $this->cache->save($cacheItem);
576
577
        $this->stopwatch->stop($cacheKey);
578
        return $totals;
579
    }
580
581
    /**
582
     * Get data for the timecard chart, with totals grouped by day and to the nearest two-hours.