CsvConverter   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 11
dl 0
loc 49
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getGlue() 0 3 1
A setGlue() 0 3 1
A convert() 0 5 1
A processCountry() 0 6 2
1
<?php
2
3
namespace MLD\Converter;
4
5
/**
6
 * Class CsvConverter
7
 */
8
class CsvConverter extends AbstractConverter
9
{
10
11
    /**
12
     * @var string
13
     */
14
    private $glue = '","';
15
16
    /**
17
     * @var string
18
     */
19
    private $body = '';
20
21
    /**
22
     * @return string data converted into CSV
23
     */
24
    public function convert()
25
    {
26
        array_walk($this->countries, [$this, 'processCountry']);
27
        $headers = '"' . implode($this->glue, array_keys($this->countries[0])) . '"';
28
        return $headers . "\n" . $this->body;
29
    }
30
31
    /**
32
     * @return string
33
     */
34
    public function getGlue()
35
    {
36
        return $this->glue;
37
    }
38
39
    /**
40
     * @param string $glue
41
     */
42
    public function setGlue($glue)
43
    {
44
        $this->glue = $glue;
45
    }
46
47
    /**
48
     * Processes a country.
49
     * @param $array
50
     */
51
    private function processCountry(&$array)
52
    {
53
        if (isset($array['currencies'])) {
54
            $array['currencies'] = array_keys($array['currencies']);
55
        }
56
        $this->body .= '"' . implode($this->glue, $this->convertArrays($array)) . "\"\n";
57
    }
58
}