Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
17 / 17
100.00% covered (success)
100.00%
5 / 5
CRAP
100.00% covered (success)
100.00%
1 / 1
FormInputInsertOperation
100.00% covered (success)
100.00%
17 / 17
100.00% covered (success)
100.00%
5 / 5
6
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getType
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getDescription
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
1
 execute
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
2
 toArray
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3/**
4 * Operation for inserting form inputs during installation.
5 *
6 * This Source Code Form is subject to the terms of the Mozilla Public License,
7 * v. 2.0. If a copy of the MPL was not distributed with this file, You can
8 * obtain one at https://mozilla.org/MPL/2.0/.
9 *
10 * @package   phpMyFAQ
11 * @author    Thorsten Rinne <thorsten@phpmyfaq.de>
12 * @copyright 2026 phpMyFAQ Team
13 * @license   https://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0
14 * @link      https://www.phpmyfaq.de
15 * @since     2026-01-31
16 */
17
18declare(strict_types=1);
19
20namespace phpMyFAQ\Setup\Migration\Operations;
21
22use phpMyFAQ\Configuration;
23use phpMyFAQ\Forms;
24use Throwable;
25
26readonly class FormInputInsertOperation implements OperationInterface
27{
28    /**
29     * @param array<string, int|string> $formInput
30     */
31    public function __construct(
32        private Configuration $configuration,
33        private array $formInput,
34    ) {
35    }
36
37    public function getType(): string
38    {
39        return 'form_input_insert';
40    }
41
42    public function getDescription(): string
43    {
44        return sprintf(
45            'Insert form input: form=%d, input=%d, label=%s',
46            $this->formInput['form_id'],
47            $this->formInput['input_id'],
48            $this->formInput['input_label'],
49        );
50    }
51
52    public function execute(): bool
53    {
54        try {
55            $forms = new Forms($this->configuration);
56            return $forms->insertInputIntoDatabase($this->formInput);
57        } catch (Throwable) {
58            return false;
59        }
60    }
61
62    public function toArray(): array
63    {
64        return [
65            'type' => $this->getType(),
66            'description' => $this->getDescription(),
67            'form_input' => $this->formInput,
68        ];
69    }
70}