ForumUserRepository   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 11
c 0
b 0
f 0
dl 0
loc 25
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A markAsRead() 0 13 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ProjetNormandie\ForumBundle\Repository;
6
7
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
8
use Doctrine\Persistence\ManagerRegistry;
9
use ProjetNormandie\ForumBundle\Entity\Forum;
10
use ProjetNormandie\ForumBundle\Entity\ForumUser;
11
12
class ForumUserRepository extends ServiceEntityRepository
13
{
14
    public function __construct(ManagerRegistry $registry)
15
    {
16
        parent::__construct($registry, ForumUser::class);
17
    }
18
19
    /**
20
     * @param            $user
21
     * @param Forum|null $forum
22
     * @return void
23
     */
24
    public function markAsRead($user, ?Forum $forum = null): void
25
    {
26
        $query = $this->_em->createQueryBuilder()
0 ignored issues
show
Bug Best Practice introduced by
The property _em does not exist on ProjetNormandie\ForumBun...ory\ForumUserRepository. Did you maybe forget to declare it?
Loading history...
27
            ->update('ProjetNormandie\ForumBundle\Entity\ForumUser', 'fu')
28
            ->set('fu.isRead', true)
29
            ->where('fu.user = :user')
30
            ->setParameter('user', $user);
31
32
        if ($forum) {
33
            $query->andWhere('fu.forum = :forum')
34
                ->setParameter('forum', $forum);
35
        }
36
        $query->getQuery()->getResult();
37
    }
38
}
39