Passed
Pull Request — master (#10)
by Paweł
03:24
created

LessonCompletedProcessor::process()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 7
nc 3
nop 2
dl 0
loc 12
rs 10
c 0
b 0
f 0
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
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, array $data): array
25
    {
26
        if ($object instanceof LessonInterface) {
27
            $userLesson = $this->userLessonRepository->getOneByUserAndLesson($this->security->getUser(), $object);
0 ignored issues
show
Bug introduced by
It seems like $this->security->getUser() can also be of type null; however, parameter $user of App\Repository\UserLesso...getOneByUserAndLesson() does only seem to accept Symfony\Component\Security\Core\User\UserInterface, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

27
            $userLesson = $this->userLessonRepository->getOneByUserAndLesson(/** @scrutinizer ignore-type */ $this->security->getUser(), $object);
Loading history...
28
            if (null === $userLesson) {
29
                $data['completed'] = null;
30
            } else {
31
                $data['completed'] = $userLesson->getCompleted();
32
            }
33
        }
34
35
        return $data;
36
    }
37
}
38