Passed
Push — master ( e66a3e...15c60f )
by Paweł
04:21
created

BookmarkRepository   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 3
eloc 12
c 1
b 0
f 1
dl 0
loc 24
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getAllForLesson() 0 7 1
A __construct() 0 3 1
A getOneById() 0 7 1
1
<?php
2
3
namespace App\Repository;
4
5
use App\Entity\Bookmark;
6
use App\Model\BookmarkInterface;
7
use App\Model\LessonInterface;
8
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
9
use Symfony\Bridge\Doctrine\RegistryInterface;
10
11
/**
12
 * @method Bookmark|null find($id, $lockMode = null, $lockVersion = null)
13
 * @method Bookmark|null findOneBy(array $criteria, array $orderBy = null)
14
 * @method Bookmark[]    findAll()
15
 * @method Bookmark[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
16
 */
17
class BookmarkRepository extends ServiceEntityRepository implements BookmarkRepositoryInterface
18
{
19
    public function __construct(RegistryInterface $registry)
20
    {
21
        parent::__construct($registry, Bookmark::class);
22
    }
23
24
    public function getAllForLesson(LessonInterface $lesson): array
25
    {
26
        return $this->createQueryBuilder('b')
27
            ->where('b.lesson = :lesson')
28
            ->setParameter('lesson', $lesson)
29
            ->getQuery()
30
            ->getResult()
31
            ;
32
    }
33
34
    public function getOneById(string $id): ?BookmarkInterface
35
    {
36
        return $this->createQueryBuilder('b')
37
        ->where('b.id = :id')
38
        ->setParameter('id', $id)
39
        ->getQuery()
40
        ->getOneOrNullResult()
41
        ;
42
    }
43
}
44