DiscussionFilter::getInputFilter()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 34

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 34
rs 9.376
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Article\Filter;
6
7
use Zend\InputFilter\InputFilter;
8
use Zend\InputFilter\InputFilterAwareInterface;
9
use Zend\InputFilter\InputFilterInterface;
10
11
class DiscussionFilter implements InputFilterAwareInterface
12
{
13
    protected $inputFilter;
14
15
    public function getInputFilter()
16
    {
17
        if (!$this->inputFilter) {
18
            $inputFilter = new InputFilter();
19
20
            $inputFilter->add(
21
                [
22
                    'name'       => 'title',
23
                    'required'   => true,
24
                    'filters'    => [['name' => 'StringTrim']],
25
                    'validators' => [
26
                        ['name' => 'NotEmpty'],
27
                        ['name' => 'StringLength', 'options' => ['min' => 2, 'max' => 100]],
28
                    ],
29
                ]
30
            );
31
32
            $inputFilter->add(
33
                [
34
                    'name'       => 'body',
35
                    'required'   => true,
36
                    'filters'    => [['name' => 'StringTrim']],
37
                    'validators' => [
38
                        ['name' => 'NotEmpty'],
39
                        ['name' => 'StringLength', 'options' => ['min' => 2, 'max' => 1500]],
40
                    ],
41
                ]
42
            );
43
44
            $this->inputFilter = $inputFilter;
45
        }
46
47
        return $this->inputFilter;
48
    }
49
50
    public function setInputFilter(InputFilterInterface $inputFilter)
51
    {
52
        throw new \Exception('Not used');
53
    }
54
}
55