Completed
Push — master ( 707446...d99c9e )
by Oleg
04:16
created

ImprovedInputFilter   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 87.5%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
lcom 0
cbo 2
dl 0
loc 24
ccs 7
cts 8
cp 0.875
rs 10
c 1
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B setData() 0 15 6
1
<?php
2
declare(strict_types=1);
3
4
namespace SlayerBirden\DataFlowServer\Zend\InputFilter;
5
6
use Zend\InputFilter\InputFilter;
7
use Zend\InputFilter\InputInterface;
8
9
class ImprovedInputFilter extends InputFilter
10
{
11
    /**
12
     * Add null values for all the inputs that were not passed.
13
     * This is needed to make optional fields still validated even when the value is not directly provided in the request.
14
     *
15
     * {@inheritdoc}
16
     */
17 15
    public function setData($data)
18
    {
19 15
        foreach ($this->getInputs() as $name => $input) {
20 15
            if ($input instanceof InputInterface) {
21 15
                if (is_numeric($name)) {
22
                    $name = $input->getName();
23
                }
24 15
                if (!empty($name) && !array_key_exists($name, $data)) {
25 7
                    $data[$name] = null;
26
                }
27
            }
28
        }
29
30 15
        return parent::setData($data);
31
    }
32
}
33