Completed
Pull Request — master (#19)
by Flo
04:59 queued 02:07
created

Text   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 6
c 3
b 0
f 0
lcom 1
cbo 1
dl 0
loc 33
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B process() 0 17 6
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 (filter_var($data, FILTER_VALIDATE_EMAIL)) {
35
            return true;
36
        }
37
38
        if (!preg_match('/^[a-z0-9\s\-_+]+$/i', $data)) {
39
            $this->errorMessage = 'validator_invalid_text';
40
            return false;
41
        }
42
43
        return !empty($data) && is_string($data) && !is_numeric($data);
44
    }
45
46
}