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

LessonRepository   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 17
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getOneById() 0 10 1
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