NotificationRepository::getEntityClass()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
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