Passed
Pull Request — master (#1181)
by Tarmo
06:39 queued 03:09
created

RequestMapper::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 0
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 1
cts 1
cp 1
crap 1
rs 10
1
<?php
2
declare(strict_types = 1);
3
/**
4
 * /src/AutoMapper/User/RequestMapper.php
5
 *
6
 * @author TLe, Tarmo Leppänen <[email protected]>
7
 */
8
9
namespace App\AutoMapper\User;
10
11
use App\AutoMapper\RestRequestMapper;
12
use App\Entity\UserGroup;
13
use App\Resource\UserGroupResource;
14
use Throwable;
15
use function array_map;
16
17
/**
18
 * Class RequestMapper
19
 *
20
 * @package App\AutoMapper
21
 * @author TLe, Tarmo Leppänen <[email protected]>
22
 */
23
class RequestMapper extends RestRequestMapper
24
{
25
    /**
26
     * @var array<int, string>
27
     */
28
    protected static array $properties = [
29
        'username',
30
        'firstName',
31
        'lastName',
32
        'email',
33
        'language',
34
        'locale',
35
        'timezone',
36
        'userGroups',
37
        'password',
38
    ];
39
40 51
    public function __construct(
41
        private UserGroupResource $userGroupResource,
42
    ) {
43 51
    }
44
45
    /**
46
     * @param array<int, string> $userGroups
47
     *
48
     * @return array<int, UserGroup>
49
     *
50
     * @throws Throwable
51
     */
52 4
    protected function transformUserGroups(array $userGroups): array
53
    {
54 4
        return array_map(
55 4
            fn (string $userGroupUuid): UserGroup => $this->userGroupResource->getReference($userGroupUuid),
56 4
            $userGroups,
57
        );
58
    }
59
}
60