Passed
Push — develop ( ef53f3...80bc53 )
by BENARD
08:34
created

GetRecentActivity   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 21
c 1
b 0
f 0
dl 0
loc 33
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 21 1
A __construct() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ProjetNormandie\ForumBundle\Controller\Topic;
6
7
use Doctrine\ORM\EntityManagerInterface;
8
use ProjetNormandie\ForumBundle\ValueObject\ForumStatus;
9
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
10
11
class GetRecentActivity extends AbstractController
12
{
13
    private EntityManagerInterface $em;
14
15
    public function __construct(EntityManagerInterface $em)
16
    {
17
        $this->em = $em;
18
    }
19
20
    /**
21
     * @return array
22
     */
23
    public function __invoke(): array
24
    {
25
        $queryBuilder = $this->em->createQueryBuilder()
26
            ->from('ProjetNormandie\ForumBundle\Entity\Topic', 't')
27
            ->select('t')
28
            ->join('t.forum', 'f')
29
            ->join('t.lastMessage', 'm')
30
            ->join('m.user', 'u')
31
            ->join('t.type', 'tt')
32
            ->addSelect('f')
33
            ->addSelect('m')
34
            ->addSelect('u')
35
            ->addSelect('tt')
36
            ->where('f.status = :status')
37
            ->andWhere('t.boolArchive = :archived')
38
            ->setParameter('status', ForumStatus::PUBLIC)
39
            ->setParameter('archived', false)
40
            ->orderBy('t.lastMessage', 'DESC')
41
            ->setMaxResults(50); // Limiter à 50 topics les plus récents
42
43
        return $queryBuilder->getQuery()->getResult();
44
    }
45
}
46