Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
13 / 13 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| GroupOlxPublicationLogger | |
100.00% |
13 / 13 |
|
100.00% |
1 / 1 |
3 | |
100.00% |
1 / 1 |
| record | |
100.00% |
13 / 13 |
|
100.00% |
1 / 1 |
3 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace ImovelZapAi\Publishing\Connectors\GroupOlx\Application\Services; |
| 6 | |
| 7 | use ImovelZapAi\Publishing\Connectors\GroupOlx\Application\Ports\GroupOlxPublicationLogWriterInterface; |
| 8 | use ImovelZapAi\Publishing\Connectors\GroupOlx\Infrastructure\Persistence\Eloquent\GroupOlxPublicationLogModel; |
| 9 | use ImovelZapAi\Publishing\Domain\Feeds\VrSync\ListingDataFeed; |
| 10 | |
| 11 | /** |
| 12 | * PublicationLogs do feed VRSync — append-only. |
| 13 | */ |
| 14 | final class GroupOlxPublicationLogger implements GroupOlxPublicationLogWriterInterface |
| 15 | { |
| 16 | /** |
| 17 | * @param list<string> $errors |
| 18 | * @param list<string> $warnings |
| 19 | */ |
| 20 | public function record( |
| 21 | string $tenantId, |
| 22 | int $listingCount, |
| 23 | int $durationMs, |
| 24 | bool $success, |
| 25 | array $errors = [], |
| 26 | array $warnings = [], |
| 27 | ?int $triggeredBy = null, |
| 28 | ?string $contentHash = null, |
| 29 | ?string $version = null, |
| 30 | ): GroupOlxPublicationLogModel { |
| 31 | /** @var GroupOlxPublicationLogModel $log */ |
| 32 | $log = GroupOlxPublicationLogModel::query()->create([ |
| 33 | 'tenant_id' => $tenantId, |
| 34 | 'triggered_by' => $triggeredBy, |
| 35 | 'listing_count' => $listingCount, |
| 36 | 'duration_ms' => max(0, $durationMs), |
| 37 | 'success' => $success, |
| 38 | 'version' => $version ?? ListingDataFeed::VERSION, |
| 39 | 'content_hash' => $contentHash, |
| 40 | 'errors' => $errors === [] ? null : array_values($errors), |
| 41 | 'warnings' => $warnings === [] ? null : array_values($warnings), |
| 42 | 'generated_at' => now(), |
| 43 | ]); |
| 44 | |
| 45 | return $log; |
| 46 | } |
| 47 | } |