Completed
Pull Request — master (#31)
by Vitaliy
02:52
created

BaseValidator::flushErrors()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 3
nc 1
nop 0
crap 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A BaseValidator::getFirstError() 0 3 2
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
     * @return bool
20
     */
21
    public abstract function isValid($value);
22
23
24
    /**
25
     * @deprecated  use new keyword instead
26
     *
27
     * @return Base
28
     */
29
    public static function i() {
30
      trigger_error('Deprecated', E_USER_DEPRECATED);
31
      return new static();
32
    }
33
34
35
    /**
36
     * @param string $message
37
     * @return $this
38
     */
39 6
    public function addError($message) {
40 6
      $this->errors[] = $message;
41 6
      return $this;
42
    }
43
44
45
    /**
46
     * @return bool
47
     */
48 1
    public function hasErrors() {
49 1
      return !empty($this->errors);
50
    }
51
52
53
    /**
54
     * @return array
55
     */
56 6
    public function getErrors() {
57 6
      return $this->errors;
58
    }
59
60
61
    /**
62
     * @return null|string
63
     */
64 2
    public function getFirstError() {
65 2
      return !empty($this->errors[0]) ? $this->errors[0] : null;
66
    }
67
  }