Passed
Push — master ( 7822f9...996de2 )
by Paweł
03:41 queued 35s
created

LessonPaginationProcessor   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 6
eloc 10
c 1
b 0
f 1
dl 0
loc 22
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A process() 0 12 5
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Serializer\Processor;
6
7
use App\Model\LessonInterface;
8
use App\Repository\LessonRepositoryInterface;
9
10
final class LessonPaginationProcessor
11
{
12
    private $lessonRepository;
13
14
    public function __construct(
15
        LessonRepositoryInterface $lessonRepository
16
    ) {
17
        $this->lessonRepository = $lessonRepository;
18
    }
19
20
    public function process(object $object, array $data): array
21
    {
22
        if ($object instanceof LessonInterface) {
23
            $previous = $this->lessonRepository->getPreviousInModule($object);
24
            $next = $this->lessonRepository->getNextInModule($object);
25
            $data['pagination'] = array_merge(isset($data['pagination']) ? $data['pagination'] : [], [
26
                'prev_lesson_id' => $previous ? $previous->getId() : null,
27
                'next_lesson_id' => $next ? $next->getId() : null,
28
            ]);
29
        }
30
31
        return $data;
32
    }
33
}
34