Completed
Pull Request — master (#143)
by
unknown
02:35
created

ContactUsFilter   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 1
dl 0
loc 78
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getInputFilter() 0 54 1
A setInputFilter() 0 5 1
1
<?php
2
3
namespace ContactUs\Filter;
4
5
use Zend\InputFilter\InputFilter;
6
use Zend\InputFilter\InputFilterAwareInterface;
7
use Zend\InputFilter\InputFilterInterface;
8
9
/**
10
 * Class ContactUsFilter
11
 *
12
 * @package ContactUs\Filter
13
 * @author  Djordje Stojiljkovic <[email protected]>
14
 */
15
class ContactUsFilter implements InputFilterAwareInterface
16
{
17
    /**
18
     * @var \Zend\InputFilter\InputFilter $inputFilter
19
     */
20
    protected $inputFilter;
21
22
    /**
23
     * @return InputFilter
24
     */
25
    public function getInputFilter()
26
    {
27
        $inputFilter = new InputFilter();
28
29
        $inputFilter
30
            ->add([
31
                'name'       => 'name',
32
                'required'   => true,
33
                'filters'    => [['name' => 'StringTrim']],
34
                'validators' => [
35
                    ['name'  => 'NotEmpty'],
36
                    ['name'  => 'StringLength', 'options' => ['min' => 1, 'max' => 255]],
37
                ],
38
            ])
39
            ->add([
40
                'name'       => 'email',
41
                'required'   => true,
42
                'filters'    => [['name' => 'StringTrim']],
43
                'validators' => [
44
                    ['name'  => 'NotEmpty'],
45
                    ['name'  => 'EmailAddress'],
46
                    ['name'  => 'StringLength', 'options' => ['min' => 2, 'max' => 100]],
47
                ]
48
            ])
49
            ->add([
50
                'name'       => 'phone',
51
                'required'   => false,
52
                'filters'    => [['name' => 'StringTrim']],
53
                'validators' => [
54
                    // TODO: PhoneNumber match cases.
55
                ]
56
            ])
57
            ->add([
58
                'name'       => 'subject',
59
                'required'   => true,
60
                'filters'    => [['name' => 'StringTrim']],
61
                'validators' => [
62
                    ['name'  => 'NotEmpty'],
63
                    ['name'  => 'StringLength', 'options' => ['min' => 5]]
64
                ]
65
            ])
66
            ->add([
67
                'name'       => 'body',
68
                'required'   => true,
69
                'filters'    => [['name' => 'StringTrim']],
70
                'validators' => [
71
                    ['name'  => 'NotEmpty'],
72
                    ['name'  => 'StringLength', 'options' => ['min' => 5]]
73
                ]
74
            ])
75
        ;
76
77
        return $inputFilter;
78
    }
79
80
    /**
81
     * @param  InputFilterInterface $inputFilter
82
     *
83
     * @return void
84
     *
85
     * @throws \Exception
86
     */
87
    public function setInputFilter(InputFilterInterface $inputFilter)
88
    {
89
        $ex = new \Exception('Not used');
90
        throw $ex;
91
    }
92
}