Passed
Pull Request — master (#1620)
by Tarmo
63:23
created

RequestMapper::transformUserGroups()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 5
ccs 1
cts 1
cp 1
crap 1
rs 10
c 0
b 0
f 0
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;
0 ignored issues
show
Bug introduced by
The type App\Enum\Language was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
14
use App\Enum\Locale;
0 ignored issues
show
Bug introduced by
The type App\Enum\Locale was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
15
use App\Resource\UserGroupResource;
16
use InvalidArgumentException;
17
use Throwable;
18
use function array_map;
19
20
/**
21
 * Class RequestMapper
22
 *
23
 * @package App\AutoMapper
24
 * @author TLe, Tarmo Leppänen <[email protected]>
25
 */
26
class RequestMapper extends RestRequestMapper
27
{
28
    /**
29
     * @var array<int, string>
30
     */
31
    protected static array $properties = [
32
        'username',
33
        'firstName',
34
        'lastName',
35
        'email',
36
        'language',
37
        'locale',
38
        'timezone',
39
        'userGroups',
40 88
        'password',
41
    ];
42
43
    public function __construct(
44
        private UserGroupResource $userGroupResource,
45
    ) {
46
    }
47
48
    /**
49
     * @param array<int, string> $userGroups
50
     *
51
     * @return array<int, UserGroup>
52 4
     *
53
     * @throws Throwable
54 4
     */
55 4
    protected function transformUserGroups(array $userGroups): array
56
    {
57
        return array_map(
58
            fn (string $userGroupUuid): UserGroup => $this->userGroupResource->getReference($userGroupUuid),
59
            $userGroups,
60
        );
61
    }
62
63
    protected function transformLanguage(string $language): Language
64
    {
65
        return Language::tryFrom($language) ?? throw new InvalidArgumentException('Invalid language');
66
    }
67
68
    protected function transformLocale(string $locale): Locale
69
    {
70
        return Locale::tryFrom($locale) ?? throw new InvalidArgumentException('Invalid locale');
71
    }
72
}
73