-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathValidation.php
More file actions
109 lines (95 loc) · 2.68 KB
/
Validation.php
File metadata and controls
109 lines (95 loc) · 2.68 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php
declare(strict_types=1);
namespace Increase\Entities\Entity;
use Increase\Core\Attributes\Required;
use Increase\Core\Concerns\SdkModel;
use Increase\Core\Contracts\BaseModel;
use Increase\Entities\Entity\Validation\Issue;
use Increase\Entities\Entity\Validation\Status;
/**
* The validation results for the entity. Learn more about [validations](/documentation/entity-validation).
*
* @phpstan-import-type IssueShape from \Increase\Entities\Entity\Validation\Issue
*
* @phpstan-type ValidationShape = array{
* issues: list<Issue|IssueShape>,
* status: \Increase\Entities\Entity\Validation\Status|value-of<\Increase\Entities\Entity\Validation\Status>,
* }
*/
final class Validation implements BaseModel
{
/** @use SdkModel<ValidationShape> */
use SdkModel;
/**
* The list of issues that need to be addressed.
*
* @var list<Issue> $issues
*/
#[Required(list: Issue::class)]
public array $issues;
/**
* The validation status for the entity. If the status is `invalid`, the `issues` array will be populated.
*
* @var value-of<Status> $status
*/
#[Required(enum: Status::class)]
public string $status;
/**
* `new Validation()` is missing required properties by the API.
*
* To enforce required parameters use
* ```
* Validation::with(issues: ..., status: ...)
* ```
*
* Otherwise ensure the following setters are called
*
* ```
* (new Validation)->withIssues(...)->withStatus(...)
* ```
*/
public function __construct()
{
$this->initialize();
}
/**
* Construct an instance from the required parameters.
*
* You must use named parameters to construct any parameters with a default value.
*
* @param list<Issue|IssueShape> $issues
* @param Status|value-of<Status> $status
*/
public static function with(
array $issues,
Status|string $status
): self {
$self = new self;
$self['issues'] = $issues;
$self['status'] = $status;
return $self;
}
/**
* The list of issues that need to be addressed.
*
* @param list<Issue|IssueShape> $issues
*/
public function withIssues(array $issues): self
{
$self = clone $this;
$self['issues'] = $issues;
return $self;
}
/**
* The validation status for the entity. If the status is `invalid`, the `issues` array will be populated.
*
* @param Status|value-of<Status> $status
*/
public function withStatus(
Status|string $status
): self {
$self = clone $this;
$self['status'] = $status;
return $self;
}
}