Code Duplication    Length = 32-34 lines in 2 locations

src/Xtools/EditCounterRepository.php 2 locations

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