IconvTransformer::transform()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3.0261

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 6
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 11
ccs 6
cts 7
cp 0.8571
crap 3.0261
rs 10
1
<?php
2
3
namespace Smart\EtlBundle\Transformer;
4
5
/**
6
 * Nicolas Bastien <[email protected]>
7
 */
8
class IconvTransformer implements TransformerInterface
9
{
10
    /**
11
     * @var string
12
     */
13
    protected $inCharset;
14
15
    /**
16
     * @var string
17
     */
18
    protected $outCharset;
19
20 1
    public function __construct($inCharset, $outCharset)
21
    {
22 1
        $this->inCharset = $inCharset;
23 1
        $this->outCharset = $outCharset;
24 1
    }
25
26
    /**
27
     * @inheritdoc
28
     */
29 1
    public function transform(array $data)
30
    {
31 1
        foreach ($data as $key => $value) {
32 1
            $convertedKey = iconv($this->inCharset, $this->outCharset, $key);
33 1
            $data[$convertedKey] = iconv($this->inCharset, $this->outCharset, $value);
34 1
            if (strcmp($key, $convertedKey) !== 0) {
35
                unset($data[$key]);
36
            }
37
        }
38
39 1
        return $data;
40
    }
41
}
42