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

Required   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setError() 0 4 1
A isValid() 0 8 4
1
<?php
2
3
  namespace Fiv\Form\Validator;
4
  
5
  /**
6
   * Check if value not empty
7
   * Algorithm based on value length
8
   *
9
   * @package Fiv\Form\Validator
10
   */
11
  class Required extends Base {
12
13
    /**
14
     * @var string
15
     */
16
    protected $error = 'Field is required ';
17
18
19
    /**
20
     * @param string $error
21
     * @return $this
22
     */
23
    public function setError($error) {
24
      $this->error = $error;
25
      return $this;
26
    }
27
28
29
    /**
30
     * @param string $value
31
     * @return bool
32
     */
33 1
    public function isValid($value) {
34
35 1
      if ((is_string($value) and strlen($value) === 0) or empty($value)) {
36 1
        $this->addError($this->error);
37
      }
38
39 1
      return !$this->hasErrors();
40
    }
41
42
  }