LessonProvider::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
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