Test Failed
Pull Request — master (#19)
by Flo
02:44
created

Text   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
c 2
b 0
f 0
lcom 1
cbo 1
dl 0
loc 29
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B process() 0 13 5
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
}