MessageRepository   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 14
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 14
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A getMessagesPublishedByReferring() 0 12 1
1
<?php
2
3
namespace PiedWeb\ConversationBundle\Repository;
4
5
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
6
use PiedWeb\ConversationBundle\Entity\MessageInterface as Message;
7
8
/*
9
 * @method Message|null find($id, $lockMode = null, $lockVersion = null)
10
 * @method Message|null findOneBy(array $criteria, array $orderBy = null)
11
 * @method Message[]    findAll()
12
 * @method Message[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
13
 */
14
class MessageRepository extends ServiceEntityRepository
15
{
16
    public function getMessagesPublishedByReferring(string $referring, $orderBy = 'createdAt DESC')
17
    {
18
        $orderBy = explode(' ', $orderBy);
19
20
        $q = $this->createQueryBuilder('m')
21
            ->andWhere('m.publishedAt is NOT NULL')
22
            ->andWhere('m.referring =  :referring')
23
            ->setParameter('referring', $referring)
24
            ->orderBy('m.'.$orderBy[0], $orderBy[1])
25
            ->getQuery();
26
27
        return $q->getResult();
28
    }
29
}
30