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

GroupMembersDataProvider   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A supports() 0 3 2
A __construct() 0 3 1
A provide() 0 11 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\Usergroup;
10
use Doctrine\ORM\EntityManagerInterface;
11
12
final class GroupMembersDataProvider implements ProviderInterface
13
{
14
    private EntityManagerInterface $entityManager;
15
16
    public function __construct(EntityManagerInterface $entityManager)
17
    {
18
        $this->entityManager = $entityManager;
19
    }
20
21
    public function supports(Operation $operation, array $uriVariables = [], array $context = []): bool
22
    {
23
        return Usergroup::class === $operation->getClass() && 'get_group_members' === $operation->getName();
24
    }
25
26
    public function provide(Operation $operation, array $uriVariables = [], array $context = []): iterable
27
    {
28
        $groupId = $uriVariables['id'] ?? null;
29
30
        if (null === $groupId) {
31
            return [];
32
        }
33
34
        $usergroupRepository = $this->entityManager->getRepository(Usergroup::class);
35
36
        return $usergroupRepository->getUsersByGroup((int) $groupId);
37
    }
38
}
39