Passed
Pull Request — master (#5)
by Paweł
03:08
created

LessonRepository::getOneById()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 8
nc 1
nop 1
dl 0
loc 10
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\Repository;
4
5
use App\Entity\Lesson;
6
use App\Model\LessonInterface;
7
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
8
use Symfony\Bridge\Doctrine\RegistryInterface;
9
10
/**
11
 * @method Lesson|null find($id, $lockMode = null, $lockVersion = null)
12
 * @method Lesson|null findOneBy(array $criteria, array $orderBy = null)
13
 * @method Lesson[]    findAll()
14
 * @method Lesson[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
15
 */
16
class LessonRepository extends ServiceEntityRepository implements LessonRepositoryInterface
17
{
18
    public function __construct(RegistryInterface $registry)
19
    {
20
        parent::__construct($registry, Lesson::class);
21
    }
22
23
    public function getOneById(string $id): ?LessonInterface
24
    {
25
        return $this->createQueryBuilder('l')
26
            ->where('l.id = :id')
27
            ->leftJoin('l.module', 'm')
28
            ->leftJoin('m.course', 'c')
29
            ->andWhere('c.visible != false')
30
            ->setParameter('id', $id)
31
            ->getQuery()
32
            ->getOneOrNullResult()
33
            ;
34
    }
35
}
36