Passed
Push — master ( 168c03...b525a2 )
by Marcel
14:55
created

InfotextRepository::removeAll()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 8
nc 2
nop 1
dl 0
loc 13
ccs 0
cts 5
cp 0
crap 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\Repository;
4
5
use App\Entity\Absence;
6
use App\Entity\Infotext;
7
use DateTime;
8
9
class InfotextRepository extends AbstractTransactionalRepository implements InfotextRepositoryInterface {
10
11
    /**
12
     * @inheritDoc
13
     */
14
    public function findAll(): array {
15
        return $this->em
16
            ->getRepository(Infotext::class)
17
            ->findAll();
18
    }
19
20
    /**
21
     * @inheritDoc
22
     */
23
    public function findAllByDate(DateTime $dateTime): array {
24
        return $this->em
25
            ->getRepository(Infotext::class)
26
            ->findBy([
27
                'date' => $dateTime
28
            ]);
29
    }
30
31
    /**
32
     * @inheritDoc
33
     */
34
    public function persist(Infotext $infotext): void {
35
        $this->em->persist($infotext);
36
        $this->flushIfNotInTransaction();
37
    }
38
39
    public function removeAll(?DateTime $dateTime = null): void {
40
        $qb = $this->em->createQueryBuilder()
41
            ->delete(Infotext::class, 'i');
42
43
        if($dateTime !== null) {
44
            $qb->where('i.date = :date')
45
                ->setParameter('date', $dateTime);
46
        }
47
48
        $qb->getQuery()
49
            ->execute();
50
51
        $this->flushIfNotInTransaction();
52
    }
53
54
    public function removeBetween(DateTime $start, DateTime $end): int {
55
        return $this->em->createQueryBuilder()
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->em->create...->getQuery()->execute() could return the type array<mixed,mixed> which is incompatible with the type-hinted return integer. Consider adding an additional type-check to rule them out.
Loading history...
56
            ->delete(Infotext::class, 'i')
57
            ->where('i.date >= :start')
58
            ->andWhere('i.date <= :end')
59
            ->setParameter('start', $start)
60
            ->setParameter('end', $end)
61
            ->getQuery()
62
            ->execute();
63
    }
64
}