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

In::setError()   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 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
cc 1
eloc 3
nc 1
nop 1
crap 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
  }