Completed
Push — develop ( 449838...84b38c )
by Alejandro
16s queued 12s
created

VisitsStatsHelper   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 6
dl 0
loc 19
ccs 7
cts 7
cp 1
rs 10
c 1
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getVisitsStats() 0 3 1
A getVisitsCount() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Shlinkio\Shlink\Core\Visit;
6
7
use Doctrine\ORM\EntityManagerInterface;
8
use Shlinkio\Shlink\Core\Entity\Visit;
9
use Shlinkio\Shlink\Core\Repository\VisitRepository;
10
use Shlinkio\Shlink\Core\Visit\Model\VisitsStats;
11
12
class VisitsStatsHelper implements VisitsStatsHelperInterface
13
{
14
    private EntityManagerInterface $em;
15
16 11
    public function __construct(EntityManagerInterface $em)
17
    {
18 11
        $this->em = $em;
19
    }
20
21 11
    public function getVisitsStats(): VisitsStats
22
    {
23 11
        return new VisitsStats($this->getVisitsCount());
24
    }
25
26 11
    private function getVisitsCount(): int
27
    {
28
        /** @var VisitRepository $visitsRepo */
29 11
        $visitsRepo = $this->em->getRepository(Visit::class);
30 11
        return $visitsRepo->count([]);
31
    }
32
}
33