Completed
Push — master ( b2cd25...08acda )
by Paweł
26s queued 10s
created

LessonProvider::getOneById()   A

Complexity

Conditions 5
Paths 2

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 8
nc 2
nop 1
dl 0
loc 13
rs 9.6111
c 0
b 0
f 0
1
<?php
2
3
namespace App\Provider;
4
5
use App\Model\LessonInterface;
6
use App\Repository\LessonRepositoryInterface;
7
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
8
9
class LessonProvider implements LessonProviderInterface
10
{
11
    private $lessonsRepository;
12
13
    public function __construct(LessonRepositoryInterface $lessonsRepository)
14
    {
15
        $this->lessonsRepository = $lessonsRepository;
16
    }
17
18
    public function getOneById(string $lessonId): LessonInterface
19
    {
20
        $lesson = $this->lessonsRepository->getOneById($lessonId);
21
        if (
22
            null === $lesson ||
23
            !$lesson->getModule() ||
24
            !$lesson->getModule()->getCourse() ||
25
            !$lesson->getModule()->getCourse()->isActive()
26
        ) {
27
            throw new NotFoundHttpException('Lesson was not found.');
28
        }
29
30
        return $lesson;
31
    }
32
}
33