Code Duplication    Length = 32-34 lines in 2 locations

src/Xtools/EditCounterRepository.php 2 locations

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