Passed
Push — master ( a5432c...54cbff )
by Marcel
16:00
created

TuitionGradeRepository::persist()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 3
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace App\Repository;
4
5
use App\Entity\Section;
6
use App\Entity\Student;
7
use App\Entity\Tuition;
8
use App\Entity\TuitionGrade;
9
use Doctrine\ORM\QueryBuilder;
10
11
class TuitionGradeRepository extends AbstractTransactionalRepository implements TuitionGradeRepositoryInterface {
12
13
    private function createDefaultQueryBuilder(): QueryBuilder {
14
        return $this->em->createQueryBuilder()
15
            ->select(['g', 't', 's', 'c'])
16
            ->from(TuitionGrade::class, 'g')
17
            ->leftJoin('g.category', 'c')
18
            ->leftJoin('g.student', 's')
19
            ->leftJoin('g.tuition', 't');
20
    }
21
22
    public function findAllByTuition(Tuition $tuition): array {
23
        return $this->createDefaultQueryBuilder()
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->createDefa...getQuery()->getResult() could return the type integer which is incompatible with the type-hinted return array. Consider adding an additional type-check to rule them out.
Loading history...
24
            ->where('t.id = :tuition')
25
            ->setParameter('tuition', $tuition->getId())
26
            ->getQuery()
27
            ->getResult();
28
    }
29
30
    public function findAllByStudent(Student $student, Section $section): array {
31
        return $this->createDefaultQueryBuilder()
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->createDefa...getQuery()->getResult() could return the type integer which is incompatible with the type-hinted return array. Consider adding an additional type-check to rule them out.
Loading history...
32
            ->leftJoin('t.section', 'sec')
33
            ->where('s.id = :student')
34
            ->andWhere('sec.id = :section')
35
            ->setParameter('student', $student->getId())
36
            ->setParameter('section', $section->getId())
37
            ->getQuery()
38
            ->getResult();
39
    }
40
41
    public function persist(TuitionGrade $grade): void {
42
        $this->em->persist($grade);
43
        $this->flushIfNotInTransaction();
44
    }
45
}