Passed
Push — master ( 50ceb2...ce9491 )
by Angel Fernando Quiroz
13:40 queued 05:22
created

MessageByGroupStateProvider::provide()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 3
dl 0
loc 9
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Chamilo\CoreBundle\State;
6
7
use ApiPlatform\Metadata\Operation;
8
use ApiPlatform\State\ProviderInterface;
9
use Chamilo\CoreBundle\Entity\Message;
10
use Chamilo\CoreBundle\Repository\MessageRepository;
11
12
/**
13
 * @template-implements ProviderInterface<array<int, Message>>
14
 */
15
final class MessageByGroupStateProvider implements ProviderInterface
16
{
17
    private MessageRepository $messageRepository;
18
19
    public function __construct(MessageRepository $messageRepository)
20
    {
21
        $this->messageRepository = $messageRepository;
22
    }
23
24
    public function supports(Operation $operation, array $uriVariables = [], array $context = []): bool
25
    {
26
        return Message::class === $operation->getClass() && 'get_messages_by_group' === $operation->getName();
27
    }
28
29
    public function provide(Operation $operation, array $uriVariables = [], array $context = []): iterable
30
    {
31
        $groupId = $context['filters']['groupId'] ?? null;
32
33
        if (null === $groupId) {
34
            return [];
35
        }
36
37
        return $this->messageRepository->getMessagesByGroup((int) $groupId, true);
38
    }
39
}
40