LessonCompletedProcessor   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 4
eloc 12
c 2
b 0
f 1
dl 0
loc 25
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A process() 0 12 3
A __construct() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Serializer\Processor;
6
7
use App\Model\LessonInterface;
8
use App\Repository\UserLessonRepositoryInterface;
9
use Symfony\Component\Security\Core\Security;
10
11
final class LessonCompletedProcessor
12
{
13
    private $userLessonRepository;
14
    private $security;
15
16
    public function __construct(
17
        UserLessonRepositoryInterface $userLessonRepository,
18
        Security $security
19
    ) {
20
        $this->userLessonRepository = $userLessonRepository;
21
        $this->security = $security;
22
    }
23
24
    public function process(object $object, array $data): array
25
    {
26
        if ($object instanceof LessonInterface) {
27
            $userLesson = $this->userLessonRepository->getOneByUserAndLesson($this->security->getUser(), $object);
28
            if (null === $userLesson) {
29
                $data['completed'] = null;
30
            } else {
31
                $data['completed'] = $userLesson->getCompleted();
32
            }
33
        }
34
35
        return $data;
36
    }
37
}
38