Completed
Push — master ( 2811d3...4b37a8 )
by Shcherbak
11:11
created

StringValidationTrait::validate()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 6
cts 6
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 6
nc 2
nop 0
crap 2
1
<?php
2
3
  declare(strict_types=1);
4
5
  namespace Fiv\Form\Validation\StringValidation;
6
7
  use Fiv\Form\Validation\ValidationResult;
8
  use Fiv\Form\Validation\ValidationResultInterface;
9
10
  trait StringValidationTrait {
11
12
    /**
13
     * @var StringValidatorInterface[]
14
     */
15
    private $validators = [];
16
17
18 2
    public function addValidator(StringValidatorInterface $validator) : self {
19 2
      $this->validators[] = $validator;
20 2
      return $this;
21
    }
22
23
24
25 2
    public function validate() : ValidationResultInterface {
26
27 2
      $validationResult = new ValidationResult();
28 2
      foreach ($this->validators as $validator) {
29 2
        $result = $validator->validate($this);
30 2
        $validationResult->merge($result);
31
      }
32
33 2
      return $validationResult;
34
    }
35
  }