aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/bakame/http-structured-fields/src/Validation/Result.php
blob: f765efda033f6e756b741595dd10a3bd7167c170 (plain) (blame)
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
<?php

declare(strict_types=1);

namespace Bakame\Http\StructuredFields\Validation;

final class Result
{
    private function __construct(
        public readonly ValidatedParameters|ValidatedItem|null $data,
        public readonly ViolationList $errors,
    ) {
    }

    public function isSuccess(): bool
    {
        return $this->errors->isEmpty();
    }

    public function isFailed(): bool
    {
        return $this->errors->isNotEmpty();
    }

    public static function success(ValidatedItem|ValidatedParameters $data): self
    {
        return new self($data, new ViolationList());
    }

    public static function failed(ViolationList $errors): self
    {
        return new self(null, $errors);
    }
}