Passed
Pull Request — master (#10)
by Paweł
03:24
created

UserLessonRepository::getOneByUserAndLesson()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 2
dl 0
loc 8
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
        return $this->createQueryBuilder('ul')
28
            ->where('ul.lesson = :lesson')
29
            ->andWhere('ul.user = :user')
30
            ->setParameters(['user' => $user, 'lesson' => $lesson])
31
            ->getQuery()
32
            ->getOneOrNullResult()
33
            ;
34
    }
35
}
36