Code Coverage
 
Lines
Branches
Paths
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
SubjectRepository
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
3 / 3
3
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 findByWordId
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 findOne
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace App\Repository;
4
5use App\Entity\Subject;
6use App\Specification\Criteria;
7use App\Specification\DoctrineQueryBuilder;
8use App\Specification\Sort;
9use App\Specification\WordCriteriaApplier;
10use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
11use Doctrine\Persistence\ManagerRegistry;
12
13/**
14 * @author Wilhelm Zwertvaegher
15 *
16 * @extends ServiceEntityRepository<Subject>
17 */
18class SubjectRepository extends ServiceEntityRepository implements SubjectRepositoryInterface
19{
20    public function __construct(ManagerRegistry $registry, private readonly WordCriteriaApplier $wordCriteriaService)
21    {
22        parent::__construct($registry, Subject::class);
23    }
24
25    public function findByWordId(int $wordId): ?Subject
26    {
27        return parent::findOneBy(['word' => $wordId]);
28    }
29
30    public function findOne(Criteria $criteria, Sort $sort = Sort::RANDOM): ?Subject
31    {
32        $qb = $this->createQueryBuilder('s')
33            ->join('s.word', 'word');
34
35        $this->wordCriteriaService->applyWordCriteria(new DoctrineQueryBuilder($qb), $criteria, $sort);
36
37        return $qb->getQuery()->getOneOrNullResult();
38    }
39}