GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

CreateUserMapper   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 9

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 9
dl 0
loc 59
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A mapToForm() 0 25 2
A mapFromForm() 0 30 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Netgen\Bundle\EzFormsBundle\Form\DataMapper;
6
7
use Netgen\Bundle\EzFormsBundle\Form\DataMapper;
8
use Netgen\Bundle\EzFormsBundle\Form\DataWrapper;
9
use RuntimeException;
10
use Symfony\Component\Form\FormInterface;
11
use Symfony\Component\PropertyAccess\PropertyPathInterface;
12
13
/**
14
 * A data mapper using property paths to read/write data.
15
 */
16
final class CreateUserMapper extends DataMapper
17
{
18
    protected function mapToForm(FormInterface $form, DataWrapper $data, PropertyPathInterface $propertyPath): void
19
    {
20
        /** @var \eZ\Publish\Core\Repository\Values\User\UserCreateStruct $userCreateStruct */
21
        $userCreateStruct = $data->payload;
22
        $contentType = $userCreateStruct->contentType;
23
24
        $fieldDefinitionIdentifier = (string) $propertyPath;
25
        $fieldDefinition = $contentType->getFieldDefinition($fieldDefinitionIdentifier);
26
27
        if (null === $fieldDefinition) {
28
            throw new RuntimeException(
29
                "Data payload does not contain expected FieldDefinition '{$fieldDefinitionIdentifier}'"
30
            );
31
        }
32
33
        $fieldTypeIdentifier = $fieldDefinition->fieldTypeIdentifier;
34
35
        $handler = $this->fieldTypeHandlerRegistry->get($fieldTypeIdentifier);
36
        $form->setData(
37
            $handler->convertFieldValueToForm(
38
                $contentType->getFieldDefinition($fieldDefinitionIdentifier)->defaultValue,
39
                $fieldDefinition
40
            )
41
        );
42
    }
43
44
    protected function mapFromForm(FormInterface $form, DataWrapper $data, PropertyPathInterface $propertyPath): void
45
    {
46
        /** @var \eZ\Publish\API\Repository\Values\User\UserCreateStruct $userCreateStruct */
47
        $userCreateStruct = $data->payload;
48
        $contentType = $userCreateStruct->contentType;
49
50
        $fieldDefinitionIdentifier = (string) $propertyPath;
51
        $fieldDefinition = $contentType->getFieldDefinition($fieldDefinitionIdentifier);
52
53
        if (null === $fieldDefinition) {
54
            throw new RuntimeException(
55
                "Data payload does not contain expected FieldDefinition '{$fieldDefinitionIdentifier}'"
56
            );
57
        }
58
59
        $fieldTypeIdentifier = $fieldDefinition->fieldTypeIdentifier;
60
61
        $handler = $this->fieldTypeHandlerRegistry->get($fieldTypeIdentifier);
62
        $convertedData = $handler->convertFieldValueFromForm($form->getData());
63
64
        // 'ezuser' is an exceptional case, here we need to map form data to the properties
65
        // in the UserCreateStruct
66
        if ($fieldTypeIdentifier === 'ezuser') {
67
            $userCreateStruct->login = $convertedData['username'];
68
            $userCreateStruct->email = $convertedData['email'];
69
            $userCreateStruct->password = $convertedData['password'] ?? null;
70
        } else {
71
            $userCreateStruct->setField($fieldDefinitionIdentifier, $convertedData);
72
        }
73
    }
74
}
75