Completed
Push — master ( 9d6293...1b9c64 )
by Tarmo
18s queued 13s
created

RequestMapper   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 40
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A transformUserGroups() 0 5 1
A transformLanguage() 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\Enum\Language;
14
use App\Resource\UserGroupResource;
15
use InvalidArgumentException;
16
use Throwable;
17
use function array_map;
18
19
/**
20
 * Class RequestMapper
21
 *
22
 * @package App\AutoMapper
23
 * @author TLe, Tarmo Leppänen <[email protected]>
24
 */
25
class RequestMapper extends RestRequestMapper
26
{
27
    /**
28
     * @var array<int, non-empty-string>
0 ignored issues
show
Documentation Bug introduced by
The doc comment array<int, non-empty-string> at position 4 could not be parsed: Unknown type name 'non-empty-string' at position 4 in array<int, non-empty-string>.
Loading history...
29
     */
30
    protected static array $properties = [
31
        'username',
32
        'firstName',
33
        'lastName',
34
        'email',
35
        'language',
36
        'locale',
37
        'timezone',
38
        'userGroups',
39
        'password',
40
    ];
41
42 96
    public function __construct(
43
        private readonly UserGroupResource $userGroupResource,
44
    ) {
45 96
    }
46
47
    /**
48
     * @param array<int, string> $userGroups
49
     *
50
     * @return array<int, UserGroup>
51
     *
52
     * @throws Throwable
53
     */
54 4
    protected function transformUserGroups(array $userGroups): array
55
    {
56 4
        return array_map(
57 4
            fn (string $userGroupUuid): UserGroup => $this->userGroupResource->getReference($userGroupUuid),
58 4
            $userGroups,
59 4
        );
60
    }
61
62 10
    protected function transformLanguage(string $language): Language
63
    {
64 10
        return Language::tryFrom($language) ?? throw new InvalidArgumentException('Invalid language');
65
    }
66
}
67