GetStats   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 18
dl 0
loc 35
rs 10
c 2
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A __invoke() 0 21 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace VideoGamesRecords\CoreBundle\Controller\Player\PlayerChart;
6
7
use Doctrine\ORM\EntityManagerInterface;
8
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
9
use Symfony\Component\HttpFoundation\Request;
10
use VideoGamesRecords\CoreBundle\Entity\Player;
11
12
class GetStats extends AbstractController
13
{
14
    protected EntityManagerInterface $em;
15
16
    public function __construct(EntityManagerInterface $em)
17
    {
18
        $this->em = $em;
19
    }
20
21
    /**
22
     * @param Player $player
23
     * @param Request $request
24
     * @return mixed
25
     */
26
    public function __invoke(Player $player, Request $request): mixed
27
    {
28
        $idGame = $request->query->get('idGame');
29
30
        $qb = $this->em->createQueryBuilder()
31
            ->select('s', 'COUNT(pc) as nb')
32
            ->from('VideoGamesRecords\CoreBundle\Entity\PlayerChartStatus', 's')
33
            ->join('s.playerCharts', 'pc')
34
            ->where('pc.player = :player')
35
            ->setParameter('player', $player)
36
            ->groupBy('s.id');
37
38
        if ($idGame !== null) {
39
            $qb->join('pc.chart', 'c')
40
                ->join('c.group', 'g')
41
                ->join('g.game', 'game')
42
                ->andWhere('game.id = :idGame')
43
                ->setParameter('idGame', (int)$idGame);
44
        }
45
46
        return $qb->getQuery()->getResult();
47
    }
48
}
49