Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
75.00% covered (warning)
75.00%
3 / 4
75.00% covered (warning)
75.00%
3 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
TranslationResult
75.00% covered (warning)
75.00%
3 / 4
75.00% covered (warning)
75.00%
3 / 4
4.25
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getTranslatedFields
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 isSuccess
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getError
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3declare(strict_types=1);
4
5/**
6 * Data Transfer Object for translation results.
7 *
8 * This Source Code Form is subject to the terms of the Mozilla Public License,
9 * v. 2.0. If a copy of the MPL was not distributed with this file, You can
10 * obtain one at https://mozilla.org/MPL/2.0/.
11 *
12 * @package   phpMyFAQ
13 * @author    Thorsten Rinne <thorsten@phpmyfaq.de>
14 * @copyright 2026 phpMyFAQ Team
15 * @license   http://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0
16 * @link      https://www.phpmyfaq.de
17 * @since     2026-01-17
18 */
19
20namespace phpMyFAQ\Translation\DTO;
21
22/**
23 * Class TranslationResult
24 *
25 * DTO for translation results containing translated fields and success status.
26 */
27readonly class TranslationResult
28{
29    /**
30     * Constructor.
31     *
32     * @param array<string, string> $translatedFields Translated fields (fieldName => translatedValue)
33     * @param bool $success Whether translation was successful
34     * @param string|null $error Error message if translation failed
35     */
36    public function __construct(
37        private array $translatedFields,
38        private bool $success,
39        private ?string $error = null,
40    ) {
41    }
42
43    /**
44     * Get translated fields.
45     *
46     * @return array<string, string>
47     */
48    public function getTranslatedFields(): array
49    {
50        return $this->translatedFields;
51    }
52
53    /**
54     * Check if the translation was successful.
55     *
56     * @return bool
57     */
58    public function isSuccess(): bool
59    {
60        return $this->success;
61    }
62
63    /**
64     * Get error message.
65     *
66     * @return string|null
67     */
68    public function getError(): ?string
69    {
70        return $this->error;
71    }
72}