• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

FluidTYPO3 / flux / 27757675993

18 Jun 2026 11:55AM UTC coverage: 89.162% (-3.5%) from 92.646%
27757675993

push

github

NamelessCoder
[TASK] Address last phpstan warnings

6228 of 6985 relevant lines covered (89.16%)

40.84 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.77
/Classes/Form/AbstractFormField.php
1
<?php
2
namespace FluidTYPO3\Flux\Form;
3

4
/*
5
 * This file is part of the FluidTYPO3/Flux project under GPLv2 or later.
6
 *
7
 * For the full copyright and license information, please read the
8
 * LICENSE.md file that was distributed with this source code.
9
 */
10

11
use FluidTYPO3\Flux\Form\Container\Section;
12
use FluidTYPO3\Flux\UserFunction\ClearValueWizard;
13
use TYPO3\CMS\Core\Utility\GeneralUtility;
14

15
abstract class AbstractFormField extends AbstractFormComponent implements FieldInterface
16
{
17
    /**
18
     * @var mixed
19
     */
20
    protected $default;
21

22
    /**
23
     * Display condition - see https://docs.typo3.org/typo3cms/TCAReference/Reference/Columns/Index.html#displaycond
24
     *
25
     * @var array|string|null
26
     */
27
    protected $displayCondition = null;
28

29
    protected bool $native = false;
30
    protected bool $required = false;
31
    protected bool $requestUpdate = false;
32
    protected bool $inherit = true;
33
    protected bool $inheritEmpty = false;
34
    protected bool $clearable = false;
35
    protected bool $protectable = false;
36
    protected bool $exclude = false;
37
    protected ?string $validate = null;
38
    protected ?string $position = null;
39
    protected array $config = [];
40

41
    public static function create(array $settings = []): FormInterface
42
    {
43
        if (!isset($settings['type'])) {
328✔
44
            $settings['type'] = static::class;
8✔
45
        }
46
        if ('Section' === $settings['type']) {
328✔
47
            return Section::create($settings);
76✔
48
        } else {
49
            $prefix = AbstractFormComponent::NAMESPACE_FIELD . '\\';
252✔
50
            $type = $settings['type'];
252✔
51
            $className = str_replace('/', '\\', $type);
252✔
52
            $className = class_exists($prefix . $className) ? $prefix . $className : $className;
252✔
53
        }
54
        if (!class_exists($className)) {
252✔
55
            $className = $settings['type'];
76✔
56
        }
57
        if (!class_exists($className)) {
252✔
58
            throw new \RuntimeException(
76✔
59
                sprintf(
76✔
60
                    'Invalid class- or type-name used in type of field "%s"; "%s" is invalid',
76✔
61
                    $settings['name'] ?? '(unknown)',
76✔
62
                    $className
76✔
63
                ),
76✔
64
                1375373527
76✔
65
            );
76✔
66
        }
67
        /** @var FieldInterface $object */
68
        $object = GeneralUtility::makeInstance($className);
176✔
69
        foreach ($settings as $settingName => $settingValue) {
176✔
70
            $setterMethodName = 'set' . ucfirst($settingName);
176✔
71
            if (true === method_exists($object, $setterMethodName)) {
176✔
72
                $object->{$setterMethodName}($settingValue);
164✔
73
            }
74
        }
75
        return $object;
176✔
76
    }
77

78
    /**
79
     * Creates a TCEforms configuration array based on the
80
     * configuration stored in this ViewHelper. Calls the
81
     * expected-to-be-overridden stub method getConfiguration()
82
     * to return the TCE field configuration - see that method
83
     * for information about how to implement that method.
84
     */
85
    public function build(): array
86
    {
87
        if (!$this->getEnabled()) {
280✔
88
            return [];
76✔
89
        }
90

91
        // The "config" section consists of whichever configuration arry the component built, but with
92
        // priority to any options set directly as raw TCA field config options in $this->config.
93
        $configuration = array_replace($this->buildConfiguration(), $this->getConfig());
204✔
94
        $filterClosure = function ($value) {
204✔
95
            return $value !== null && $value !== '' && $value !== [];
200✔
96
        };
204✔
97
        $configuration = array_filter($configuration, $filterClosure);
204✔
98
        $fieldStructureArray = [
204✔
99
            'label' => $this->getLabel(),
204✔
100
            'exclude' => intval($this->getExclude()),
204✔
101
            'config' => $configuration
204✔
102
        ];
204✔
103
        if (($description = $this->getDescription()) && $description !== null) {
204✔
104
            $fieldStructureArray['description'] = $this->getDescription();
4✔
105
        }
106
        if (($displayCondition = $this->getDisplayCondition())) {
204✔
107
            $fieldStructureArray['displayCond'] = $displayCondition;
4✔
108
        }
109

110
        if ($this->getClearable()) {
204✔
111
            $fieldStructureArray['config']['fieldWizard']['fluxClearValue'] = [
76✔
112
                'renderType' => 'fluxClearValue',
76✔
113
            ];
76✔
114
        }
115

116
        if ($this->getProtectable() && $this->getInherit()) {
204✔
117
            $fieldStructureArray['config']['fieldWizard']['fluxProtectValue'] = [
×
118
                'renderType' => 'fluxProtectValue',
×
119
            ];
×
120
        }
121

122
        if ($this->getRequestUpdate()) {
204✔
123
            $fieldStructureArray['onChange'] = 'reload';
36✔
124
        }
125
        return $fieldStructureArray;
204✔
126
    }
127

128
    protected function prepareConfiguration(string $type): array
129
    {
130
        $config = [
208✔
131
            'type' => $type,
208✔
132
            'transform' => $this->getTransform(),
208✔
133
            'default' => $this->getDefault(),
208✔
134
        ];
208✔
135
        if ($this->getRequired()) {
208✔
136
            $config['required'] = $this->getRequired();
16✔
137
        }
138
        return $config;
208✔
139
    }
140

141
    public function isNative(): bool
142
    {
143
        return $this->native;
24✔
144
    }
145

146
    public function setNative(bool $native): self
147
    {
148
        $this->native = $native;
180✔
149
        return $this;
180✔
150
    }
151

152
    public function setRequired(bool $required): self
153
    {
154
        $this->required = $required;
192✔
155
        return $this;
192✔
156
    }
157

158
    public function getRequired(): bool
159
    {
160
        return $this->required;
208✔
161
    }
162

163
    /**
164
     * @param mixed $default
165
     */
166
    public function setDefault($default): self
167
    {
168
        $this->default = $default;
336✔
169
        return $this;
336✔
170
    }
171

172
    /**
173
     * @return mixed
174
     */
175
    public function getDefault()
176
    {
177
        return $this->default;
236✔
178
    }
179

180
    /**
181
     * @param string|array|null $displayCondition
182
     */
183
    public function setDisplayCondition($displayCondition): self
184
    {
185
        $this->displayCondition = $displayCondition;
204✔
186
        return $this;
204✔
187
    }
188

189
    /**
190
     * @return string|array|null
191
     */
192
    public function getDisplayCondition()
193
    {
194
        return $this->displayCondition;
212✔
195
    }
196

197
    public function setRequestUpdate(bool $requestUpdate): self
198
    {
199
        $this->requestUpdate = $requestUpdate;
372✔
200
        return $this;
372✔
201
    }
202

203
    public function getRequestUpdate(): bool
204
    {
205
        return $this->requestUpdate;
224✔
206
    }
207

208
    public function setExclude(bool $exclude): self
209
    {
210
        $this->exclude = $exclude;
188✔
211
        return $this;
188✔
212
    }
213

214
    public function getExclude(): bool
215
    {
216
        return $this->exclude;
212✔
217
    }
218

219
    public function setValidate(?string $validate): self
220
    {
221
        $this->validate = $validate;
224✔
222
        return $this;
224✔
223
    }
224

225
    public function getConfig(): array
226
    {
227
        return $this->config;
212✔
228
    }
229

230
    public function setConfig(array $config): self
231
    {
232
        $this->config = $config;
200✔
233
        return $this;
200✔
234
    }
235

236
    public function getValidate(): ?string
237
    {
238
        return $this->validate;
80✔
239
    }
240

241
    public function getPosition(): ?string
242
    {
243
        return $this->position;
4✔
244
    }
245

246
    public function setPosition(?string $position): self
247
    {
248
        $this->position = $position;
180✔
249
        return $this;
180✔
250
    }
251

252
    public function setClearable(bool $clearable): self
253
    {
254
        $this->clearable = (bool) $clearable;
340✔
255
        return $this;
340✔
256
    }
257

258
    public function getClearable(): bool
259
    {
260
        return $this->clearable;
292✔
261
    }
262

263
    public function getProtectable(): bool
264
    {
265
        return $this->protectable;
204✔
266
    }
267

268
    public function setProtectable(bool $protectable): self
269
    {
270
        $this->protectable = $protectable;
188✔
271
        return $this;
188✔
272
    }
273
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc