Passed
Push — develop ( cfccb6...0b3512 )
by BENARD
04:54
created

GetWebsiteStats   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 15
dl 0
loc 34
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A __invoke() 0 21 1
1
<?php
2
3
namespace VideoGamesRecords\CoreBundle\Controller;
4
5
use Doctrine\ORM\EntityManagerInterface;
6
use Doctrine\ORM\NonUniqueResultException;
7
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
8
use VideoGamesRecords\CoreBundle\Repository\GameRepository;
9
use VideoGamesRecords\CoreBundle\Repository\PlayerRepository;
10
use VideoGamesRecords\CoreBundle\Repository\TeamRepository;
11
12
class GetWebsiteStats extends AbstractController
13
{
14
    protected EntityManagerInterface $em;
15
16
    public function __construct(EntityManagerInterface $em)
17
    {
18
        $this->em = $em;
19
    }
20
21
    /**
22
     * @return array
23
     * @throws NonUniqueResultException
24
     */
25
    public function __invoke(): array
26
    {
27
        /** @var PlayerRepository $playerRepository */
28
        $playerRepository = $this->em->getRepository('VideoGamesRecords\CoreBundle\Entity\Player');
29
30
        /** @var GameRepository $gameRepository */
31
        $gameRepository = $this->em->getRepository('VideoGamesRecords\CoreBundle\Entity\Game');
32
33
        /** @var TeamRepository $teamRepository */
34
        $teamRepository = $this->em->getRepository('VideoGamesRecords\CoreBundle\Entity\Team');
35
36
        $playerStats = $playerRepository->getStats();
37
        $gameStats = $gameRepository->getStats();
38
        $teamStats = $teamRepository->getStats();
39
40
        return array(
41
            'nbPlayer' => $playerStats[1],
42
            'nbChart' => $playerStats[2],
43
            'nbChartProven' => $playerStats[3],
44
            'nbGame' => $gameStats[1],
45
            'nbTeam' => $teamStats[1],
46
        );
47
    }
48
}
49