Code Duplication    Length = 32-34 lines in 2 locations

src/Xtools/EditCounterRepository.php 2 locations

@@ 464-497 (lines=34) @@
461
     * @param User $user The user.
462
     * @return string[]
463
     */
464
    public function getMonthCounts(Project $project, User $user)
465
    {
466
        $username = $user->getUsername();
467
        $cacheKey = "monthcounts.$username";
468
        $this->stopwatch->start($cacheKey, 'XTools');
469
        if ($this->cache->hasItem($cacheKey)) {
470
            return $this->cache->getItem($cacheKey)->get();
471
        }
472
473
        $revisionTable = $this->getTableName($project->getDatabaseName(), 'revision');
474
        $pageTable = $this->getTableName($project->getDatabaseName(), 'page');
475
        $sql =
476
            "SELECT "
477
            . "     YEAR(rev_timestamp) AS `year`,"
478
            . "     MONTH(rev_timestamp) AS `month`,"
479
            . "     page_namespace,"
480
            . "     COUNT(rev_id) AS `count` "
481
            .  " FROM $revisionTable JOIN $pageTable ON (rev_page = page_id)"
482
            . " WHERE rev_user_text = :username"
483
            . " GROUP BY YEAR(rev_timestamp), MONTH(rev_timestamp), page_namespace "
484
            . " ORDER BY rev_timestamp DESC";
485
        $resultQuery = $this->getProjectsConnection()->prepare($sql);
486
        $resultQuery->bindParam(":username", $username);
487
        $resultQuery->execute();
488
        $totals = $resultQuery->fetchAll();
489
        
490
        $cacheItem = $this->cache->getItem($cacheKey);
491
        $cacheItem->expiresAfter(new DateInterval('PT10M'));
492
        $cacheItem->set($totals);
493
        $this->cache->save($cacheItem);
494
495
        $this->stopwatch->stop($cacheKey);
496
        return $totals;
497
    }
498
499
    /**
500
     * Get yearly edit totals for this user, grouped by namespace.
@@ 505-536 (lines=32) @@
502
     * @param User $user The user.
503
     * @return string[] ['<namespace>' => ['<year>' => 'total', ... ], ... ]
504
     */
505
    public function getYearCounts(Project $project, User $user)
506
    {
507
        $username = $user->getUsername();
508
        $cacheKey = "yearcounts.$username";
509
        $this->stopwatch->start($cacheKey, 'XTools');
510
        if ($this->cache->hasItem($cacheKey)) {
511
            return $this->cache->getItem($cacheKey)->get();
512
        }
513
514
        $revisionTable = $this->getTableName($project->getDatabaseName(), 'revision');
515
        $pageTable = $this->getTableName($project->getDatabaseName(), 'page');
516
        $sql = "SELECT "
517
            . "     YEAR(rev_timestamp) AS `year`,"
518
            . "     page_namespace,"
519
            . "     COUNT(rev_id) AS `count` "
520
            . " FROM $revisionTable JOIN $pageTable ON (rev_page = page_id)"
521
            . " WHERE rev_user_text = :username"
522
            . " GROUP BY YEAR(rev_timestamp), page_namespace "
523
            . " ORDER BY rev_timestamp DESC ";
524
        $resultQuery = $this->getProjectsConnection()->prepare($sql);
525
        $resultQuery->bindParam(":username", $username);
526
        $resultQuery->execute();
527
        $totals = $resultQuery->fetchAll();
528
529
        $cacheItem = $this->cache->getItem($cacheKey);
530
        $cacheItem->set($totals);
531
        $cacheItem->expiresAfter(new DateInterval('P10M'));
532
        $this->cache->save($cacheItem);
533
534
        $this->stopwatch->stop($cacheKey);
535
        return $totals;
536
    }
537
538
    /**
539
     * Get data for the timecard chart, with totals grouped by day and to the nearest two-hours.