Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
14 / 14
100.00% covered (success)
100.00%
8 / 8
CRAP
100.00% covered (success)
100.00%
1 / 1
GroupOlxPublicationLogData
100.00% covered (success)
100.00%
14 / 14
100.00% covered (success)
100.00%
8 / 8
12
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
 generatedAtLabel
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 durationLabel
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
 responsibleLabel
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
4
 errorsLabel
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 warningsLabel
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 hasErrors
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 hasWarnings
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5namespace ImovelZapAi\Publishing\Connectors\GroupOlx\Application\Data;
6
7use Carbon\CarbonInterface;
8
9/**
10 * Linha de PublicationLog do Grupo OLX para o painel.
11 */
12final readonly class GroupOlxPublicationLogData
13{
14    /**
15     * @param  list<string>  $errors
16     * @param  list<string>  $warnings
17     */
18    public function __construct(
19        public string $id,
20        public string $tenantId,
21        public ?int $triggeredById,
22        public ?string $triggeredByName,
23        public int $listingCount,
24        public int $durationMs,
25        public bool $success,
26        public string $version,
27        public ?string $contentHash,
28        public array $errors,
29        public array $warnings,
30        public CarbonInterface $generatedAt,
31    ) {}
32
33    public function generatedAtLabel(): string
34    {
35        return $this->generatedAt
36            ->timezone(config('app.timezone'))
37            ->format('d/m/Y H:i');
38    }
39
40    public function durationLabel(): string
41    {
42        if ($this->durationMs < 1000) {
43            return $this->durationMs.' ms';
44        }
45
46        return number_format($this->durationMs / 1000, 2, ',', '.').' s';
47    }
48
49    public function responsibleLabel(): string
50    {
51        if ($this->triggeredByName !== null && $this->triggeredByName !== '') {
52            return $this->triggeredByName;
53        }
54
55        return $this->triggeredById !== null ? 'Usuário #'.$this->triggeredById : 'Sistema';
56    }
57
58    public function errorsLabel(): string
59    {
60        return $this->errors[0] ?? '—';
61    }
62
63    public function warningsLabel(): string
64    {
65        return $this->warnings[0] ?? '—';
66    }
67
68    public function hasErrors(): bool
69    {
70        return $this->errors !== [];
71    }
72
73    public function hasWarnings(): bool
74    {
75        return $this->warnings !== [];
76    }
77}