BaseValidator   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
c 0
b 0
f 0
lcom 1
cbo 0
dl 0
loc 48
ccs 0
cts 13
cp 0
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
isValid() 0 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
   *
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
  }