Completed
Push — master ( 0c5536...d4f264 )
by
unknown
15s queued 10s
created

IconvTransformer::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
c 0
b 0
f 0
ccs 4
cts 4
cp 1
rs 10
cc 1
nc 1
nop 2
crap 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 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 1
                unset($data[$key]);
36
            }
37
        }
38
39 1
        return $data;
40
    }
41
}
42