ObjectEntryRepository::save()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Infrastructure\Persistence\Repository;
6
7
use App\Infrastructure\Persistence\Entity\ObjectEntry;
8
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
9
use Doctrine\Persistence\ManagerRegistry;
10
11
class ObjectEntryRepository extends ServiceEntityRepository
12
{
13 10
    public function __construct(ManagerRegistry $registry)
14
    {
15 10
        parent::__construct($registry, ObjectEntry::class);
16 10
    }
17
18 9
    public function save(ObjectEntry $entry): void
19
    {
20 9
        $this->_em->persist($entry);
21 9
        $this->_em->flush();
22 9
    }
23
24 9
    public function deleteAll(): void
25
    {
26 9
        $this->createQueryBuilder('e')
27 9
            ->delete()
28 9
            ->getQuery()
29 9
            ->execute();
30 9
    }
31
32 8
    public function findByKeyAtTime(string $key, \DateTime $time): ?ObjectEntry
33
    {
34 8
        return $this->createQueryBuilder('e')
35 8
            ->andWhere('e.key = :key')
36 8
            ->andWhere('e.createdAt <= :time')
37 8
            ->setParameters(['key' => $key, 'time' => $time])
38 8
            ->orderBy('e.createdAt', 'DESC')
39 8
            ->setMaxResults(1)
40 8
            ->getQuery()
41 8
            ->getOneOrNullResult();
42
    }
43
}
44