Text   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 34
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 0 16 5
1
<?php
2
3
namespace Faulancer\Form\Validator\Base;
4
5
use Faulancer\Form\Validator\AbstractValidator;
6
7
/**
8
 * Class Text
9
 *
10
 * @package Faulancer\Form\Validator\Base
11
 * @author Florian Knapp <[email protected]>
12
 */
13
class Text extends AbstractValidator
14
{
15
16
    /**
17
     * The error message as key for translation
18
     * @var string
19
     */
20
    protected $errorMessage = 'validator_invalid_text';
21
22
    /**
23
     * Validate type string
24
     *
25
     * @param $data
26
     *
27
     * @return bool
28
     */
29
    public function process($data)
30
    {
31
        if (empty($data)) {
32
            $this->errorMessage = 'validator_empty_text';
33
        }
34
35
        if (filter_var($data, FILTER_VALIDATE_EMAIL)) {
36
            return true;
37
        }
38
39
        if (!preg_match('/^([a-zA-Z0-9äüöÄÖÜŠĐČĆŽšđčćž\s\/\-_+.,:°;()²³]+)$/ui', $data)) {
40
            return false;
41
        }
42
43
        return !empty($data) && is_string($data);
44
    }
45
46
}