Code Duplication    Length = 32-34 lines in 2 locations

src/Xtools/EditCounterRepository.php 2 locations

@@ 441-474 (lines=34) @@
438
     * @param string $username The username.
439
     * @return string[]
440
     */
441
    public function getMonthCounts(Project $project, User $user)
442
    {
443
        $username = $user->getUsername();
444
        $cacheKey = "monthcounts.$username";
445
        $this->stopwatch->start($cacheKey, 'XTools');
446
        if ($this->cache->hasItem($cacheKey)) {
447
            return $this->cache->getItem($cacheKey)->get();
448
        }
449
450
        $revisionTable = $this->getTableName($project->getDatabaseName(), 'revision');
451
        $pageTable = $this->getTableName($project->getDatabaseName(), 'page');
452
        $sql =
453
            "SELECT "
454
            . "     YEAR(rev_timestamp) AS `year`,"
455
            . "     MONTH(rev_timestamp) AS `month`,"
456
            . "     page_namespace,"
457
            . "     COUNT(rev_id) AS `count` "
458
            .  " FROM $revisionTable JOIN $pageTable ON (rev_page = page_id)"
459
            . " WHERE rev_user_text = :username"
460
            . " GROUP BY YEAR(rev_timestamp), MONTH(rev_timestamp), page_namespace "
461
            . " ORDER BY rev_timestamp DESC";
462
        $resultQuery = $this->getProjectsConnection()->prepare($sql);
463
        $resultQuery->bindParam(":username", $username);
464
        $resultQuery->execute();
465
        $totals = $resultQuery->fetchAll();
466
        
467
        $cacheItem = $this->cache->getItem($cacheKey);
468
        $cacheItem->expiresAfter(new DateInterval('PT10M'));
469
        $cacheItem->set($totals);
470
        $this->cache->save($cacheItem);
471
472
        $this->stopwatch->stop($cacheKey);
473
        return $totals;
474
    }
475
476
    /**
477
     * Get yearly edit totals for this user, grouped by namespace.
@@ 482-513 (lines=32) @@
479
     * @param User $user
480
     * @return string[] ['<namespace>' => ['<year>' => 'total', ... ], ... ]
481
     */
482
    public function getYearCounts(Project $project, User $user)
483
    {
484
        $username = $user->getUsername();
485
        $cacheKey = "yearcounts.$username";
486
        $this->stopwatch->start($cacheKey, 'XTools');
487
        if ($this->cache->hasItem($cacheKey)) {
488
            return $this->cache->getItem($cacheKey)->get();
489
        }
490
491
        $revisionTable = $this->getTableName($project->getDatabaseName(), 'revision');
492
        $pageTable = $this->getTableName($project->getDatabaseName(), 'page');
493
        $sql = "SELECT "
494
            . "     YEAR(rev_timestamp) AS `year`,"
495
            . "     page_namespace,"
496
            . "     COUNT(rev_id) AS `count` "
497
            . " FROM $revisionTable JOIN $pageTable ON (rev_page = page_id)"
498
            . " WHERE rev_user_text = :username"
499
            . " GROUP BY YEAR(rev_timestamp), page_namespace "
500
            . " ORDER BY rev_timestamp DESC ";
501
        $resultQuery = $this->getProjectsConnection()->prepare($sql);
502
        $resultQuery->bindParam(":username", $username);
503
        $resultQuery->execute();
504
        $totals = $resultQuery->fetchAll();
505
506
        $cacheItem = $this->cache->getItem($cacheKey);
507
        $cacheItem->set($totals);
508
        $cacheItem->expiresAfter(new DateInterval('P10M'));
509
        $this->cache->save($cacheItem);
510
511
        $this->stopwatch->stop($cacheKey);
512
        return $totals;
513
    }
514
515
    /**
516
     * Get data for the timecard chart, with totals grouped by day and to the nearest two-hours.