ScheduledMessageRepository::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 1
c 2
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Setono\MessageSchedulerBundle\Repository;
6
7
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
8
use Doctrine\Persistence\ManagerRegistry;
9
use Safe\DateTime;
10
use Setono\MessageSchedulerBundle\Entity\ScheduledMessage;
11
12
class ScheduledMessageRepository extends ServiceEntityRepository implements ScheduledMessageRepositoryInterface
13
{
14 1
    public function __construct(ManagerRegistry $registry)
15
    {
16 1
        parent::__construct($registry, ScheduledMessage::class);
17 1
    }
18
19
    public function findDispatchable(): array
20
    {
21
        return $this->createQueryBuilder('o')
22
            ->andWhere('o.dispatchAt <= :now')
23
            ->andWhere('o.state = :state')
24
            ->setParameter('now', new DateTime())
25
            ->setParameter('state', ScheduledMessage::STATE_PENDING)
26
            ->setMaxResults(100) // this is just a very basic 'hack' to prevent memory problems
27
            ->getQuery()
28
            ->getResult()
29
        ;
30
    }
31
}
32