EmptyToNullConverter::convert()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 0
cts 6
cp 0
rs 10
c 0
b 0
f 0
cc 2
nc 1
nop 1
crap 6
1
<?php
2
3
namespace Mathielen\DataImport\ItemConverter;
4
5
use Ddeboer\DataImport\ItemConverter\ItemConverterInterface;
6
7
class EmptyToNullConverter implements ItemConverterInterface
8
{
9
    /**
10
     * Convert an input.
11
     *
12
     * @param mixed $input Input
13
     *
14
     * @return array|null the modified input or null to remove it
15
     */
16
    public function convert($input)
17
    {
18
        return array_filter($input, function ($col) {
19
            return !is_scalar($col) || trim($col) !== ''; /* dont use empty() - would convert "0" */
20
        });
21
    }
22
}
23