Lines
100.00%
17 / 17
Methods
100.00%
5 / 5
Classes
100.00%
1 / 1
| Name | Lines | Methods | CRAP | ||||
|---|---|---|---|---|---|---|---|
| __construct | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| getType | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| getDescription | 100.00% | 6 / 6 | 100.00% | 1 / 1 | 1 | ||
| execute | 100.00% | 4 / 4 | 100.00% | 1 / 1 | 2 | ||
| toArray | 100.00% | 5 / 5 | 100.00% | 1 / 1 | 1 | ||
| 26 | readonly 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 | } |