Completed
Push — master ( 38a590...33903f )
by Shcherbak
06:56
created

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