Completed
Push — master ( 15d409...38a590 )
by Shcherbak
05:57 queued 13s
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 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 0
cts 0
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
   * @package Fiv\Form\Validator
9
   */
10
  class In extends Base {
11
12
    /**
13
     * @var string
14
     */
15
    protected $error = 'Invalid value';
16
17
    /**
18
     * @var array
19
     */
20
    protected $values = [];
21
22
23
    /**
24
     * @param array $values
25
     * @return $this
26
     */
27 1
    public function setValues($values) {
28 1
      $this->values = $values;
29 1
      return $this;
30
    }
31
32
33
    /**
34
     * @param string $error
35
     * @return $this
36
     */
37
    public function setError($error) {
38
      $this->error = $error;
39
      return $this;
40
    }
41
42
43
    /**
44
     * @param string $value
45
     * @return bool
46
     */
47 1
    public function isValid($value) {
48
49 1
      if (!in_array($value, $this->values)) {
50 1
        $this->addError($this->error);
51
      }
52
53 1
      return !$this->hasErrors();
54
    }
55
56
  }