Completed
Push — master ( a64142...aa4ae5 )
by Paweł
13s queued 10s
created

UserLessonRepository::getOneByUserAndLesson()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 8
nc 2
nop 2
dl 0
loc 12
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\Repository;
4
5
use App\Entity\UserLesson;
6
use App\Model\LessonInterface;
7
use App\Model\UserLessonInterface;
8
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
9
use Symfony\Bridge\Doctrine\RegistryInterface;
10
use Symfony\Component\Security\Core\User\UserInterface;
11
12
/**
13
 * @method UserLesson|null find($id, $lockMode = null, $lockVersion = null)
14
 * @method UserLesson|null findOneBy(array $criteria, array $orderBy = null)
15
 * @method UserLesson[]    findAll()
16
 * @method UserLesson[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
17
 */
18
class UserLessonRepository extends ServiceEntityRepository implements UserLessonRepositoryInterface
19
{
20
    public function __construct(RegistryInterface $registry)
21
    {
22
        parent::__construct($registry, UserLesson::class);
23
    }
24
25
    public function getOneByUserAndLesson(?UserInterface $user, LessonInterface $lesson): ?UserLessonInterface
26
    {
27
        if (null === $user) {
28
            return null;
29
        }
30
31
        return $this->createQueryBuilder('ul')
32
            ->where('ul.lesson = :lesson')
33
            ->andWhere('ul.user = :user')
34
            ->setParameters(['user' => $user, 'lesson' => $lesson])
35
            ->getQuery()
36
            ->getOneOrNullResult()
37
            ;
38
    }
39
}
40