-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathResultDto.php
56 lines (44 loc) · 1.06 KB
/
ResultDto.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
declare(strict_types=1);
namespace Rechtlogisch\Steuernummer\Abstracts;
abstract class ResultDto
{
private ?bool $valid = null;
/** @var string[]|null */
private ?array $errors = null;
public function isValid(): ?bool
{
return $this->valid;
}
public function setValid(bool $valid): void
{
$this->valid = $valid;
}
/**
* @return array<string, string>|null
*/
public function getErrors(): ?array
{
return $this->errors;
}
public function getFirstErrorKey(): ?string
{
return (string) array_key_first($this->errors ?? []);
}
/**
* @return array<string, string>|null
*/
public function getFirstError(): ?array
{
$errors = $this->getErrors() ?? [];
$firstKey = array_key_first($errors);
if ($firstKey === null) {
return null;
}
return [$firstKey => $errors[$firstKey]];
}
public function addError(string $type, string $error): void
{
$this->errors[$type] = $error;
}
}