Completed
Pull Request — develop (#745)
by Alejandro
05:29
created

VisitsStatsHelper::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 1
b 0
f 0
cc 1
nc 1
nop 1
crap 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