Completed
Push — master ( 15d409...38a590 )
by Shcherbak
05:57 queued 13s
created

In   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 4
c 3
b 0
f 0
lcom 1
cbo 1
dl 0
loc 47
ccs 7
cts 7
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setValues() 0 4 1
A setError() 0 4 1
A isValid() 0 8 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
  }