Code Duplication    Length = 32-34 lines in 2 locations

src/Xtools/EditCounterRepository.php 2 locations

@@ 419-452 (lines=34) @@
416
     * @param string $username The username.
417
     * @return string[]
418
     */
419
    public function getMonthCounts(Project $project, User $user)
420
    {
421
        $username = $user->getUsername();
422
        $cacheKey = "monthcounts.$username";
423
        $this->stopwatch->start($cacheKey, 'XTools');
424
        if ($this->cache->hasItem($cacheKey)) {
425
            return $this->cache->getItem($cacheKey)->get();
426
        }
427
428
        $revisionTable = $this->getTableName($project->getDatabaseName(), 'revision');
429
        $pageTable = $this->getTableName($project->getDatabaseName(), 'page');
430
        $sql =
431
            "SELECT "
432
            . "     YEAR(rev_timestamp) AS `year`,"
433
            . "     MONTH(rev_timestamp) AS `month`,"
434
            . "     page_namespace,"
435
            . "     COUNT(rev_id) AS `count` "
436
            .  " FROM $revisionTable JOIN $pageTable ON (rev_page = page_id)"
437
            . " WHERE rev_user_text = :username"
438
            . " GROUP BY YEAR(rev_timestamp), MONTH(rev_timestamp), page_namespace "
439
            . " ORDER BY rev_timestamp DESC";
440
        $resultQuery = $this->getProjectsConnection()->prepare($sql);
441
        $resultQuery->bindParam(":username", $username);
442
        $resultQuery->execute();
443
        $totals = $resultQuery->fetchAll();
444
        
445
        $cacheItem = $this->cache->getItem($cacheKey);
446
        $cacheItem->expiresAfter(new DateInterval('PT10M'));
447
        $cacheItem->set($totals);
448
        $this->cache->save($cacheItem);
449
450
        $this->stopwatch->stop($cacheKey);
451
        return $totals;
452
    }
453
454
    /**
455
     * Get yearly edit totals for this user, grouped by namespace.
@@ 460-491 (lines=32) @@
457
     * @param User $user
458
     * @return string[] ['<namespace>' => ['<year>' => 'total', ... ], ... ]
459
     */
460
    public function getYearCounts(Project $project, User $user)
461
    {
462
        $username = $user->getUsername();
463
        $cacheKey = "yearcounts.$username";
464
        $this->stopwatch->start($cacheKey, 'XTools');
465
        if ($this->cache->hasItem($cacheKey)) {
466
            return $this->cache->getItem($cacheKey)->get();
467
        }
468
469
        $revisionTable = $this->getTableName($project->getDatabaseName(), 'revision');
470
        $pageTable = $this->getTableName($project->getDatabaseName(), 'page');
471
        $sql = "SELECT "
472
            . "     YEAR(rev_timestamp) AS `year`,"
473
            . "     page_namespace,"
474
            . "     COUNT(rev_id) AS `count` "
475
            . " FROM $revisionTable JOIN $pageTable ON (rev_page = page_id)"
476
            . " WHERE rev_user_text = :username"
477
            . " GROUP BY YEAR(rev_timestamp), page_namespace "
478
            . " ORDER BY rev_timestamp DESC ";
479
        $resultQuery = $this->getProjectsConnection()->prepare($sql);
480
        $resultQuery->bindParam(":username", $username);
481
        $resultQuery->execute();
482
        $totals = $resultQuery->fetchAll();
483
484
        $cacheItem = $this->cache->getItem($cacheKey);
485
        $cacheItem->set($totals);
486
        $cacheItem->expiresAfter(new DateInterval('P10M'));
487
        $this->cache->save($cacheItem);
488
489
        $this->stopwatch->stop($cacheKey);
490
        return $totals;
491
    }
492
493
    /**
494
     * Get data for the timecard chart, with totals grouped by day and to the nearest two-hours.