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

EmptyToNullConverter   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 0%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A convert() 0 6 2
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