Text::process()   A
last analyzed

Complexity

Conditions 5
Paths 8

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.4222
c 0
b 0
f 0
cc 5
nc 8
nop 1
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
}