Passed
Push — master ( bcea47...3c36a2 )
by Julito
11:00
created

UserItemDataProvider::getItem()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 4
dl 0
loc 7
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
/* For licensing terms, see /license.txt */
6
7
namespace Chamilo\CoreBundle\DataProvider;
8
9
use ApiPlatform\Core\DataProvider\ItemDataProviderInterface;
10
use ApiPlatform\Core\DataProvider\RestrictedDataProviderInterface;
11
use Chamilo\CoreBundle\Component\Utils\NameConvention;
12
use Chamilo\CoreBundle\Entity\User;
13
use Chamilo\CoreBundle\Repository\Node\UserRepository;
14
15
class UserItemDataProvider implements ItemDataProviderInterface, RestrictedDataProviderInterface
16
{
17
    public function __construct(
18
        private UserRepository $repository,
19
        private NameConvention $nameConvention
20
    ) {
21
    }
22
23
    public function getItem(string $resourceClass, $id, string $operationName = null, array $context = [])
24
    {
25
        $user = $this->repository->find($id);
26
27
        $this->nameConvention->getPersonName($user);
28
29
        return $user;
30
    }
31
32
    public function supports(string $resourceClass, string $operationName = null, array $context = []): bool
33
    {
34
        return User::class === $resourceClass;
35
    }
36
}
37