FieldValue   A
last analyzed

Complexity

Total Complexity 15

Size/Duplication

Total Lines 82
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 24
dl 0
loc 82
rs 10
c 0
b 0
f 0
wmc 15

9 Methods

Rating   Name   Duplication   Size   Complexity  
A getField() 0 3 1
A setField() 0 3 1
A getValueForCsvExport() 0 10 4
A getValueType() 0 3 1
A getValue() 0 12 4
A getRegistration() 0 3 1
A setValueType() 0 3 1
A setValue() 0 3 1
A setRegistration() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Extension "sf_event_mgt" for TYPO3 CMS.
7
 *
8
 * For the full copyright and license information, please read the
9
 * LICENSE.txt file that was distributed with this source code.
10
 */
11
12
namespace DERHANSEN\SfEventMgt\Domain\Model\Registration;
13
14
use DERHANSEN\SfEventMgt\Domain\Model\Registration;
15
use DERHANSEN\SfEventMgt\Utility\ArrayUtility;
16
use DERHANSEN\SfEventMgt\Utility\FieldValueType;
17
use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;
0 ignored issues
show
Bug introduced by
The type TYPO3\CMS\Extbase\DomainObject\AbstractEntity 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...
18
19
class FieldValue extends AbstractEntity
20
{
21
    /**
22
     * Annotation is required, so propertyMapper will find a suiteable typeConverter
23
     *
24
     * @var string
25
     */
26
    protected string $value = '';
27
28
    protected int $valueType = FieldValueType::TYPE_TEXT;
29
    protected ?Field $field = null;
30
    protected ?Registration $registration = null;
31
32
    /**
33
     * Returns value depending on the valueType
34
     *
35
     * @return string|array
36
     */
37
    public function getValue()
38
    {
39
        $value = $this->value;
40
        if ($this->getField() && $this->getField()->getValueType() === FieldValueType::TYPE_ARRAY) {
41
            if (ArrayUtility::isJsonArray($value)) {
42
                $value = json_decode($value, true);
43
            } else {
44
                $value = [$this->value];
45
            }
46
        }
47
48
        return $value;
49
    }
50
51
    /**
52
     * Returns the field value for CSV export
53
     *
54
     * @return string
55
     */
56
    public function getValueForCsvExport(): string
57
    {
58
        $value = $this->value;
59
        if ($this->getField() && $this->getField()->getValueType() === FieldValueType::TYPE_ARRAY &&
60
            ArrayUtility::isJsonArray($value)
61
        ) {
62
            $value = implode(',', json_decode($value, true));
63
        }
64
65
        return $value;
66
    }
67
68
    public function setValue(string $value): void
69
    {
70
        $this->value = $value;
71
    }
72
73
    public function getField(): ?Field
74
    {
75
        return $this->field;
76
    }
77
78
    public function setField(?Field $field): void
79
    {
80
        $this->field = $field;
81
    }
82
83
    public function getRegistration(): ?Registration
84
    {
85
        return $this->registration;
86
    }
87
88
    public function setRegistration(?Registration $registration): void
89
    {
90
        $this->registration = $registration;
91
    }
92
93
    public function getValueType(): int
94
    {
95
        return $this->valueType;
96
    }
97
98
    public function setValueType(int $valueType): void
99
    {
100
        $this->valueType = $valueType;
101
    }
102
}
103