NotificationRepository   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 13
c 1
b 0
f 0
dl 0
loc 25
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getEntityClass() 0 3 1
A findUnread() 0 18 2
1
<?php
2
3
namespace JK\NotificationBundle\Repository;
4
5
use Doctrine\Common\Collections\ArrayCollection;
6
use Doctrine\Common\Collections\Collection;
7
use JK\NotificationBundle\Entity\Notification;
8
use JK\Repository\AbstractRepository;
9
10
class NotificationRepository extends AbstractRepository
11
{
12
    public function findUnread(string $ownerId = null): Collection
13
    {
14
        $queryBuilder = $this
15
            ->createQueryBuilder('notification')
16
            ->where('notification.read = :read')
17
            ->setParameter('read', false)
18
            ->addOrderBy('notification.updatedAt', 'desc')
19
            ->addOrderBy('notification.id', 'desc')
20
        ;
21
22
        if ($ownerId) {
23
            $queryBuilder
24
                ->andWhere('notification.ownerId = :owner_id')
25
                ->setParameter('owner_id', $ownerId)
26
            ;
27
        }
28
29
        return new ArrayCollection($queryBuilder->getQuery()->getResult());
30
    }
31
32
    public function getEntityClass(): string
33
    {
34
        return Notification::class;
35
    }
36
}
37