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

GroupMembersDataProvider::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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