Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
42.31% covered (danger)
42.31%
11 / 26
50.00% covered (danger)
50.00%
1 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
ImportResultDto
44.00% covered (danger)
44.00%
11 / 25
50.00% covered (danger)
50.00%
1 / 2
2.70
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
11 / 11
100.00% covered (success)
100.00%
1 / 1
1
 toArray
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3declare(strict_types=1);
4
5/** @license For full copyright and license information, please see the LICENSE.md file. */
6
7namespace App\Core\DataExchange\Domain\Model;
8
9defined('AMMONLY_APP') || exit('Direct script access is forbidden.');
10
11/**
12 * Data Transfer Object containing the metrics and error logs of an import operation.
13 *
14 * @package App\Core\DataExchange\Domain\Model
15 */
16final readonly class ImportResultDto
17{
18    public bool $success;
19    public int $totalRows;
20    public int $insertedRows;
21    public int $importedRows;
22    public int $updatedRows;
23    public int $skippedRows;
24    public int $errorRows;
25    public int $failedRows;
26    /** @var list<array{row: int, message: string}> */
27    public array $errors;
28    public bool $dryRun;
29    public ?int $jobId;
30
31    /**
32     * ImportResultDto constructor.
33     *
34     * @param bool                                   $success      True if completed without fatal abort.
35     * @param int                                    $totalRows    Total rows parsed from source file.
36     * @param int                                    $importedRows Newly imported/inserted record count.
37     * @param int                                    $updatedRows  Updated existing record count.
38     * @param int                                    $skippedRows  Skipped duplicate or blank row count.
39     * @param int                                    $failedRows   Rows rejected due to validation failure.
40     * @param list<array{row: int, message: string}> $errors       Detailed row-level error log.
41     */
42    public function __construct(
43        bool $success = true,
44        int $totalRows = 0,
45        int $importedRows = 0,
46        int $updatedRows = 0,
47        int $skippedRows = 0,
48        int $failedRows = 0,
49        array $errors = []
50    ) {
51        $this->success = $success;
52        $this->totalRows = $totalRows;
53        $this->importedRows = $importedRows;
54        $this->insertedRows = $importedRows;
55        $this->updatedRows = $updatedRows;
56        $this->skippedRows = $skippedRows;
57        $this->failedRows = $failedRows;
58        $this->errorRows = $failedRows;
59        $this->errors = $errors;
60        $this->dryRun = false;
61        $this->jobId = null;
62    }
63
64    /**
65     * Serializes result object to an array.
66     *
67     * @return array{
68     *     success: bool,
69     *     total_rows: int,
70     *     inserted_rows: int,
71     *     imported_rows: int,
72     *     updated_rows: int,
73     *     skipped_rows: int,
74     *     error_rows: int,
75     *     failed_rows: int,
76     *     errors_count: int,
77     *     errors: list<array{row: int, message: string}>,
78     *     dry_run: bool,
79     *     job_id: int|null
80     * }
81     */
82    public function toArray(): array
83    {
84        return [
85            'success'       => $this->success,
86            'total_rows'    => $this->totalRows,
87            'inserted_rows' => $this->insertedRows,
88            'imported_rows' => $this->importedRows,
89            'updated_rows'  => $this->updatedRows,
90            'skipped_rows'  => $this->skippedRows,
91            'error_rows'    => $this->errorRows,
92            'failed_rows'   => $this->failedRows,
93            'errors_count'  => count($this->errors),
94            'errors'        => $this->errors,
95            'dry_run'       => $this->dryRun,
96            'job_id'        => $this->jobId,
97        ];
98    }
99}