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

ValidationResult   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 90%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 0
dl 0
loc 30
ccs 9
cts 10
cp 0.9
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 2
A isOk() 0 4 1
A getErrors() 0 4 1
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