Completed
Pull Request — master (#10)
by Nicolas
01:11
created

IconvTransformer::transform()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.8666
c 0
b 0
f 0
cc 3
nc 3
nop 1
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
    public function __construct($inCharset, $outCharset)
21
    {
22
        $this->inCharset = $inCharset;
23
        $this->outCharset = $outCharset;
24
    }
25
26
    /**
27
     * @inheritdoc
28
     */
29
    public function transform(array $data)
30
    {
31
        foreach ($data as $key => $value) {
32
            $convertedKey = iconv($this->inCharset, $this->outCharset, $key);
33
            $data[$convertedKey] = iconv($this->inCharset, $this->outCharset, $value);
34
            if (strcmp($key, $convertedKey) !== 0) {
35
                unset($data[$key]);
36
            }
37
        }
38
39
        return $data;
40
    }
41
}
42