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

Required::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
   * 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
  }