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

ImprovedInputFilter::setData()   B

Complexity

Conditions 6
Paths 6

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 6.0702

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 15
ccs 7
cts 8
cp 0.875
rs 8.8571
c 1
b 0
f 0
cc 6
eloc 8
nc 6
nop 1
crap 6.0702
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