RegisterFilter::getInputFilter()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 66

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 66
rs 8.7418
c 0
b 0
f 0
cc 1
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Register\Filter;
4
5
use Zend\InputFilter\InputFilter;
6
use Zend\InputFilter\InputFilterAwareInterface;
7
use Zend\InputFilter\InputFilterInterface;
8
9
class RegisterFilter implements InputFilterAwareInterface
10
{
11
    protected $inputFilter;
12
13
    public function getInputFilter()
14
    {
15
        $inputFilter = new InputFilter();
16
17
        $inputFilter->add(
18
            [
19
                'name'       => 'full_name',
20
                'required'   => true,
21
                'filters'    => [['name' => 'StringTrim'], ['name' => 'StripTags'], ['name' => 'StripNewlines']],
22
                'validators' => [
23
                    ['name' => 'NotEmpty'],
24
                    ['name' => 'StringLength', 'options' => ['min' => 2, 'max' => 1000]],
25
                ],
26
            ]
27
        );
28
29
        $inputFilter->add(
30
            [
31
                'name'       => 'email',
32
                'required'   => true,
33
                'filters'    => [['name' => 'StringTrim'], ['name' => 'StripTags'], ['name' => 'StripNewlines']],
34
                'validators' => [
35
                    ['name' => 'NotEmpty'],
36
                    ['name' => 'EmailAddress'],
37
                ],
38
            ]
39
        );
40
41
        $inputFilter->add(
42
            [
43
                'name'       => 'phone',
44
                'required'   => true,
45
                'filters'    => [['name' => 'StringTrim'], ['name' => 'StripTags'], ['name' => 'StripNewlines']],
46
                'validators' => [
47
                    ['name' => 'NotEmpty'],
48
                    ['name' => 'StringLength', 'options' => ['min' => 2, 'max' => 30]],
49
                ],
50
            ]
51
        );
52
53
        $inputFilter->add(
54
            [
55
                'name'       => 'url',
56
                'required'   => true,
57
                'filters'    => [['name' => 'StringTrim'], ['name' => 'StripTags'], ['name' => 'StripNewlines']],
58
                'validators' => [
59
                    ['name' => 'NotEmpty'],
60
                    ['name' => 'StringLength', 'options' => ['min' => 2, 'max' => 1000]],
61
                ],
62
            ]
63
        );
64
65
        $inputFilter->add(
66
            [
67
                'name'       => 'cover_letter',
68
                'required'   => true,
69
                'filters'    => [['name' => 'StringTrim'], ['name' => 'StripTags'], ['name' => 'StripNewlines']],
70
                'validators' => [
71
                    ['name' => 'NotEmpty'],
72
                    ['name' => 'StringLength', 'options' => ['min' => 10, 'max' => 10000]],
73
                ],
74
            ]
75
        );
76
77
        return $inputFilter;
78
    }
79
80
    public function setInputFilter(InputFilterInterface $inputFilter)
81
    {
82
        throw new \Exception('Not used');
83
    }
84
}