BaseValidator::getFirstError()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 2

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 3
ccs 0
cts 3
cp 0
rs 10
cc 2
eloc 2
nc 2
nop 0
crap 6
1
<?php
2
3
  namespace Fiv\Form\Validator;
4
5
  /**
6
   *
7
   * @author Ivan Shcherbak <[email protected]>
8
   */
9
  abstract class BaseValidator implements ValidatorInterface {
0 ignored issues
show
Deprecated Code introduced by
The interface Fiv\Form\Validator\ValidatorInterface has been deprecated with message: Use new Elements and new Validators

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
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
    public function addError($message) {
29
      $this->errors[] = $message;
30
      return $this;
31
    }
32
33
34
    /**
35
     * @return bool
36
     */
37
    public function hasErrors() {
38
      return !empty($this->errors);
39
    }
40
41
42
    /**
43
     * @return array
44
     */
45
    public function getErrors() {
46
      return $this->errors;
47
    }
48
49
50
    /**
51
     * @return null|string
52
     */
53
    public function getFirstError() {
54
      return !empty($this->errors[0]) ? $this->errors[0] : null;
55
    }
56
  }