Passed
Push — master ( f8b703...5f4fe5 )
by Lee
01:29
created

EmptyString   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 20
dl 0
loc 35
ccs 0
cts 13
cp 0
rs 10
c 0
b 0
f 0
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A isValid() 0 21 4
1
<?php
2
3
namespace Lavibi\Popoya;
4
5
class EmptyString extends AbstractValidator
6
{
7
    const E_NOT_EMPTY = 'empty';
8
    const E_NOT_STRING = 'not_string';
9
10
    protected $messages = [
11
        self::E_NOT_EMPTY => 'The given value is not empty string.',
12
        self::E_NOT_STRING => 'The given value is not string.'
13
    ];
14
15
    protected $defaultOptions = [
16
        'trim' => true
17
    ];
18
19
    public function isValid($value)
20
    {
21
        $this->standardValue = null;
22
        $this->value = $value;
23
24
        if (!is_string($this->value)) {
25
            $this->setError(static::E_NOT_STRING);
26
            return false;
27
        }
28
29
        if ($this->options['trim'] === true) {
30
            $this->value = trim($this->value);
31
        }
32
33
        if ($this->value !== '') {
34
            $this->setError(static::E_NOT_EMPTY);
35
            return false;
36
        }
37
38
        $this->standardValue = $this->value;
39
        return true;
40
    }
41
}
42