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

BaseValidator   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 75%

Importance

Changes 5
Bugs 1 Features 0
Metric Value
wmc 6
c 5
b 1
f 0
lcom 1
cbo 0
dl 0
loc 59
ccs 9
cts 12
cp 0.75
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
isValid() 0 1 ?
A i() 0 4 1
A addError() 0 4 1
A hasErrors() 0 3 1
A getErrors() 0 3 1
A 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
  }