VideoFilter::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 VideoFilter 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'       => 'sub_title',
35
                    'required'   => false,
36
                    'filters'    => [['name' => 'StringTrim']],
37
                    'validators' => [
38
                        ['name' => 'NotEmpty'],
39
                        ['name' => 'StringLength', 'options' => ['min' => 2, 'max' => 500]],
40
                    ],
41
                ]
42
            );
43
44
            $inputFilter->add(
45
                [
46
                    'name'       => 'body',
47
                    'required'   => true,
48
                    'filters'    => [['name' => 'StringTrim']],
49
                    'validators' => [
50
                        ['name' => 'NotEmpty'],
51
                        ['name' => 'StringLength', 'options' => ['min' => 2]],
52
                    ],
53
                ]
54
            );
55
56
            $inputFilter->add(
57
                [
58
                    'name'       => 'lead',
59
                    'required'   => true,
60
                    'filters'    => [['name' => 'StringTrim']],
61
                    'validators' => [
62
                        ['name' => 'NotEmpty'],
63
                        ['name' => 'StringLength', 'options' => ['min' => 2]],
64
                    ],
65
                ]
66
            );
67
68
            $inputFilter->add(
69
                [
70
                    'name'       => 'video_url',
71
                    'required'   => true,
72
                    'filters'    => [['name' => 'StringTrim']],
73
                    'validators' => [
74
                        ['name' => 'NotEmpty'],
75
                        ['name' => 'StringLength'],
76
                    ],
77
                ]
78
            );
79
80
            $this->inputFilter = $inputFilter;
81
        }
82
83
        return $this->inputFilter;
84
    }
85
86
    public function setInputFilter(InputFilterInterface $inputFilter)
87
    {
88
        throw new \Exception('Not used');
89
    }
90
}
91