Passed
Push — main ( cfbbfd...11bc17 )
by Breno
01:46
created

ValidationResult::withErrors()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 5
rs 10
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 withErrors(string ...$error): self
17
    {
18
        $instance = new self;
19
        $instance->errors = $error;
20
        return $instance;
21
    }
22
23
    public function error(string ...$errors): self
24
    {
25
        $instance = clone $this;
26
        array_push($instance->errors, ...$errors);
27
        return $instance;
28
    }
29
30
    /**
31
     * @inheritDoc
32
     */
33
    public function isOk(): bool
34
    {
35
        return empty($this->errors);
36
    }
37
38
    /**
39
     * @inheritDoc
40
     */
41
    public function getErrors(): array
42
    {
43
        return $this->errors;
44
    }
45
}
46