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

MessageByGroupDataProvider::supports()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 1
c 1
b 0
f 0
nc 2
nop 3
dl 0
loc 3
rs 10
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