Completed
Push — master ( 3cc3b2...768def )
by Vitaliy
01:53
created

BaseValidator   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
c 0
b 0
f 0
lcom 1
cbo 0
dl 0
loc 48
ccs 9
cts 9
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
isValid() 0 1 ?
A addError() 0 4 1
A hasErrors() 0 3 1
A getErrors() 0 3 1
A getFirstError() 0 3 2
1
<?php
2
3
  namespace Fiv\Form\Validator;
4
5
  /**
6
   *
7
   * @author Ivan Shcherbak <[email protected]>
8
   */
9
  abstract class BaseValidator implements ValidatorInterface {
10
11
    /**
12
     * @var array
13
     */
14
    protected $errors = [];
15
16
17
    /**
18
     * @param string $value
19
     * @return bool
20
     */
21
    public abstract function isValid($value);
22
23
24
    /**
25
     * @param string $message
26
     * @return $this
27
     */
28 6
    public function addError($message) {
29 6
      $this->errors[] = $message;
30 6
      return $this;
31
    }
32
33
34
    /**
35
     * @return bool
36
     */
37 1
    public function hasErrors() {
38 1
      return !empty($this->errors);
39
    }
40
41
42
    /**
43
     * @return array
44
     */
45 6
    public function getErrors() {
46 6
      return $this->errors;
47
    }
48
49
50
    /**
51
     * @return null|string
52
     */
53 2
    public function getFirstError() {
54 2
      return !empty($this->errors[0]) ? $this->errors[0] : null;
55
    }
56
  }