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.

CreateContentMapper::mapFromForm()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 23

Duplication

Lines 23
Ratio 100 %

Importance

Changes 0
Metric Value
dl 23
loc 23
rs 9.552
c 0
b 0
f 0
cc 2
nc 2
nop 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 View Code Duplication
final class CreateContentMapper extends DataMapper
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
17
{
18
    protected function mapToForm(FormInterface $form, DataWrapper $data, PropertyPathInterface $propertyPath): void
19
    {
20
        /** @var \eZ\Publish\Core\Repository\Values\Content\ContentCreateStruct $contentCreateStruct */
21
        $contentCreateStruct = $data->payload;
22
        $contentType = $contentCreateStruct->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\Core\Repository\Values\Content\ContentCreateStruct $contentCreateStruct */
47
        $contentCreateStruct = $data->payload;
48
        $contentType = $contentCreateStruct->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
        $contentCreateStruct->setField(
63
            $fieldDefinitionIdentifier,
64
            $handler->convertFieldValueFromForm($form->getData())
65
        );
66
    }
67
}
68