Completed
Push — master ( 2c052a...11c889 )
by Shcherbak
11s
created

In   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
c 0
b 0
f 0
lcom 1
cbo 1
dl 0
loc 49
ccs 0
cts 16
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setValues() 0 4 1
A setError() 0 4 1
A isValid() 0 10 2
1
<?php
2
3
  namespace Fiv\Form\Validator;
4
5
6
  /**
7
   * @author Ivan Shcherbak <[email protected]>
8
   */
9
  class In extends BaseValidator {
10
11
    /**
12
     * @var string
13
     */
14
    protected $error = 'Invalid value';
15
16
    /**
17
     * @var array
18
     */
19
    protected $values = [];
20
21
22
    /**
23
     * @param array $values
24
     * @return $this
25
     */
26
    public function setValues($values) {
27
      $this->values = $values;
28
      return $this;
29
    }
30
31
32
    /**
33
     * @param string $error
34
     * @return $this
35
     */
36
    public function setError($error) {
37
      $this->error = $error;
38
      return $this;
39
    }
40
41
42
    /**
43
     * @param string $value
44
     * @return bool
45
     */
46
    public function isValid($value) {
47
      $this->errors = [];
48
49
      if (in_array($value, $this->values)) {
50
        return true;
51
      }
52
53
      $this->addError($this->error);
54
      return false;
55
    }
56
57
  }