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

BaseValidator::i()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 4
rs 10
ccs 0
cts 3
cp 0
cc 1
eloc 3
nc 1
nop 0
crap 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
  }