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

IconvTransformer   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 0
dl 0
loc 34
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A transform() 0 12 3
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