Completed
Push — master ( a2c256...20e03b )
by Shcherbak
02:35
created

BaseValidator::hasErrors()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
  namespace Fiv\Form\Validator;
4
5
  /**
6
   * @package Fiv\Form
7
   * @author Ivan Shcherbak <[email protected]> 2016
8
   */
9
  abstract class BaseValidator implements ValidatorInterface {
10
11
    /**
12
     * @var array
13
     */
14
    protected $errors = [];
15
16
17
    /**
18
     * @param string $value
19
     */
20
    public abstract function isValid($value);
21
22
23
    /**
24
     * @deprecated  use new keyword instead
25
     *
26
     * @return Base
27
     */
28
    public static function i() {
29
      trigger_error('Deprecated', E_USER_DEPRECATED);
30
      return new static();
31
    }
32
33
34
    /**
35
     * @param string $message
36
     * @return Base
37
     */
38 5
    public function addError($message) {
39 5
      $this->errors[] = $message;
40 5
      return $this;
41
    }
42
43
44
    /**
45
     * @return bool
46
     */
47 4
    public function hasErrors() {
48 4
      return !empty($this->errors);
49
    }
50
51
52
    /**
53
     * @return array
54
     */
55
    public function getErrors() {
56
      return $this->errors;
57
    }
58
59
60
    /**
61
     * @return Base
62
     */
63 5
    public function flushErrors() {
64 5
      $this->errors = [];
65 5
      return $this;
66
    }
67
68
69
    /**
70
     * @return null|string
71
     */
72 1
    public function getFirstError() {
73 1
      return !empty($this->errors[0]) ? $this->errors[0] : null;
74
    }
75
  }