Passed
Push — main ( 013e60...00f274 )
by Breno
01:56
created

ValidationResult::withError()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace BrenoRoosevelt\Validation;
5
6
class ValidationResult implements Result
7
{
8
    /** @var string[] */
9
    private array $errors = [];
10
11
    public static function everythingIsOk(): self
12
    {
13
        return new self;
14
    }
15
16
    public static function withError(string ...$error): self
17
    {
18
        return (new self)->error(...$error);
19
    }
20
21
    public function error(string ...$errors): self
22
    {
23
        array_push($this->errors, ...$errors);
24
        return $this;
25
    }
26
27
    /**
28
     * @inheritDoc
29
     */
30
    public function isOk(): bool
31
    {
32
        return empty($this->errors);
33
    }
34
35
    /**
36
     * @inheritDoc
37
     */
38
    public function getErrors(): array
39
    {
40
        return $this->errors;
41
    }
42
}
43