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

Regexp   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

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

3 Methods

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