ValidationResult::merge()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 6
ccs 0
cts 6
cp 0
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
crap 6
1
<?php
2
3
  declare(strict_types=1);
4
5
  namespace Fiv\Form\Validation;
6
7
  class ValidationResult implements ValidationResultInterface {
8
9
    /**
10
     * @var string[]
11
     */
12
    private $errors = [];
13
14
15
    public function merge(ValidationResultInterface $validationResult) : self {
16
      foreach ($validationResult->getErrors() as $error) {
17
        $this->addError($error);
18
      }
19
      return $this;
20
    }
21
22
23
    public function addError(string $error) : self {
24
      $this->errors[] = $error;
25
      return $this;
26
    }
27
28
29
    public function getErrors() {
30
      return $this->errors;
31
    }
32
33
34
    public function isValid() : bool {
35
      return empty($this->errors);
36
    }
37
38
  }