Completed
Push — master ( b95665...0485d1 )
by Markus
07:03
created

EmptyToNullConverter::convert()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
ccs 0
cts 6
cp 0
rs 9.4285
cc 2
eloc 3
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