PostFilter::setInputFilter()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
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 PostFilter 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' => 100000]],
40
                    ],
41
                ]
42
            );
43
44
            $inputFilter->add(
45
                [
46
                    'name'       => 'lead',
47
                    'required'   => true,
48
                    'filters'    => [['name' => 'StringTrim']],
49
                    'validators' => [
50
                        ['name' => 'NotEmpty'],
51
                        ['name' => 'StringLength', 'options' => ['min' => 2, 'max' => 50000]],
52
                    ],
53
                ]
54
            );
55
56
            $inputFilter->add(
57
                [
58
                    'name'     => 'has_layout',
59
                    'required' => false,
60
                    'filters'  => [['name' => 'Boolean']],
61
                ]
62
            );
63
64
            $this->inputFilter = $inputFilter;
65
        }
66
67
        return $this->inputFilter;
68
    }
69
70
    public function setInputFilter(InputFilterInterface $inputFilter)
71
    {
72
        throw new \Exception('Not used');
73
    }
74
}
75