Completed
Pull Request — master (#61)
by Michal
02:15
created

ValidationResult::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2.0185

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 5
cts 6
cp 0.8333
rs 9.9666
c 0
b 0
f 0
cc 2
nc 2
nop 2
crap 2.0185
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Tomaj\NetteApi\ValidationResult;
6
7
use InvalidArgumentException;
8
9
class ValidationResult implements ValidationResultInterface
10
{
11
    const STATUS_OK = 'OK';
12
13
    const STATUS_ERROR = 'error';
14
15
    private $status;
16
17
    private $errors = [];
18
19 33
    public function __construct(string $status, array $errors = [])
20
    {
21 33
        if (!in_array($status, [self::STATUS_OK, self::STATUS_ERROR], true)) {
22
            throw new InvalidArgumentException($status . ' is not valid validation result status');
23
        }
24
25 33
        $this->status = $status;
26 33
        $this->errors = $errors;
27 33
    }
28
29 33
    public function isOk(): bool
30
    {
31 33
        return $this->status === self::STATUS_OK;
32
    }
33
34 21
    public function getErrors(): array
35
    {
36 21
        return $this->errors;
37
    }
38
}
39