Test Failed
Pull Request — master (#19)
by Flo
04:22
created

Text::process()   B

Complexity

Conditions 5
Paths 8

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 13
rs 8.8571
cc 5
eloc 7
nc 8
nop 1
1
<?php
2
/**
3
 * Class Text | Text.php
4
 * @package Faulancer\Form\Validator\Base
5
 * @author Florian Knapp <[email protected]>
6
 */
7
namespace Faulancer\Form\Validator\Base;
8
9
use Faulancer\Form\Validator\AbstractValidator;
10
11
/**
12
 * Class Text
13
 */
14
class Text extends AbstractValidator
15
{
16
17
    /**
18
     * The error message as key for translation
19
     * @var string
20
     */
21
    protected $errorMessage = 'validator_invalid_text';
22
23
    /**
24
     * Validate type string
25
     * @param $data
26
     * @return boolean
27
     */
28
    public function process($data)
29
    {
30
        if (empty($data)) {
31
            $this->errorMessage = 'validator_empty_text';
32
        }
33
34
        if (!preg_match('/^[a-z0-9\s\-_]+$/i', $data)) {
35
            $this->errorMessage = 'validator_invalid_text';
36
            return false;
37
        }
38
39
        return !empty($data) && is_string($data) && !is_numeric($data);
40
    }
41
42
}