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

FreeTimespanRepository::removeAll()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 14
ccs 0
cts 7
cp 0
rs 9.9666
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 6
1
<?php
2
3
namespace App\Repository;
4
5
use App\Entity\FreeTimespan;
6
use DateTime;
7
8
class FreeTimespanRepository extends AbstractTransactionalRepository implements FreeTimespanRepositoryInterface {
9
10
    /**
11
     * @inheritDoc
12
     */
13
    public function findAllByDate(DateTime $dateTime): array {
14
        return $this->em->getRepository(FreeTimespan::class)
15
            ->findBy([
16
                'date' => $dateTime
17
            ]);
18
    }
19
20
    /**
21
     * @inheritDoc
22
     */
23
    public function findAll(): array {
24
        return $this->em->getRepository(FreeTimespan::class)
25
            ->findAll();
26
    }
27
28
    public function persist(FreeTimespan $timespan): void {
29
        $this->em->persist($timespan);
30
        $this->flushIfNotInTransaction();
31
    }
32
33
    public function removeAll(?DateTime $dateTime): void {
34
        $qb = $this->em->createQueryBuilder()
35
            ->delete(FreeTimespan::class, 't');
36
37
        if($dateTime !== null) {
38
            $qb->where('t.date = :date')
39
                ->setParameter('date', $dateTime);
40
        }
41
42
        $qb
43
            ->getQuery()
44
            ->execute();
45
46
        $this->flushIfNotInTransaction();
47
    }
48
49
    public function removeBetween(DateTime $start, DateTime $end): int {
50
        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...
51
            ->delete(FreeTimespan::class, 't')
52
            ->where('t.date >= :start')
53
            ->andWhere('t.date <= :end')
54
            ->setParameter('start', $start)
55
            ->setParameter('end', $end)
56
            ->getQuery()
57
            ->execute();
58
    }
59
}