EmptyValueToNullTransformer   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 8
lcom 0
cbo 0
dl 0
loc 23
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B transform() 0 17 8
1
<?php
2
3
namespace TreeHouse\Feeder\Modifier\Data\Transformer;
4
5
/**
6
 * Transforms empty values to null. This is not the exact equivalent of the
7
 * empty() function. The difference is that this transformer will leave 0 and
8
 * false alone, as they could be valid feed values.
9
 */
10
class EmptyValueToNullTransformer implements TransformerInterface
11
{
12
    /**
13
     * @inheritdoc
14
     */
15 28
    public function transform($value)
16
    {
17
        // let booleans, integers and floats pass
18 28
        if (is_null($value) || is_bool($value) || is_integer($value) || is_float($value)) {
19 12
            return $value;
20
        }
21
22 16
        if (is_string($value)) {
23 12
            if (trim($value) === '') {
24 4
                return;
25
            }
26 14
        } elseif (empty($value)) {
27 2
            return;
28
        }
29
30 12
        return $value;
31
    }
32
}
33