Passed
Push — dependabot/github_actions/code... ( 154cc6...3e3012 )
by
unknown
26:36 queued 15:59
created

MessageByGroupDataProvider   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 23
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A supports() 0 3 2
A provide() 0 9 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Chamilo\CoreBundle\DataProvider;
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
final class MessageByGroupDataProvider implements ProviderInterface
13
{
14
    private MessageRepository $messageRepository;
15
16
    public function __construct(MessageRepository $messageRepository)
17
    {
18
        $this->messageRepository = $messageRepository;
19
    }
20
21
    public function supports(Operation $operation, array $uriVariables = [], array $context = []): bool
22
    {
23
        return Message::class === $operation->getClass() && 'get_messages_by_group' === $operation->getName();
24
    }
25
26
    public function provide(Operation $operation, array $uriVariables = [], array $context = []): iterable
27
    {
28
        $groupId = $context['filters']['groupId'] ?? null;
29
30
        if (null === $groupId) {
31
            return [];
32
        }
33
34
        return $this->messageRepository->findByGroupId((int) $groupId);
35
    }
36
}
37