Completed
Pull Request — master (#61)
by Tomas
02:14
created

ValidationResult::isOk()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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