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

RequestMapper   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 13
c 0
b 0
f 0
dl 0
loc 34
ccs 6
cts 6
cp 1
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A transformUserGroups() 0 5 1
A __construct() 0 3 1
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