Completed
Pull Request — master (#61)
by Tomas
02:14
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
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