WriteCurrencyInfoMapFiles::writeSubMaps()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 4
nc 1
nop 1
crap 1
1
<?php
2
3
namespace VinaiKopp\CurrencyInfo\Build;
4
5
class WriteCurrencyInfoMapFiles
6
{
7
    /**
8
     * @var CurrencyInfoSource
9
     */
10
    private $source;
11
12
    /**
13
     * @var \SplFileInfo
14
     */
15
    private $outputDir;
16
17 1
    public function __construct(CurrencyInfoSource $source, \SplFileInfo $outputDir)
18
    {
19 1
        $this->source = $source;
20 1
        $this->outputDir = $outputDir;
21 1
    }
22
23 1
    public function write(CurrencyInfoKeys $currencyInfoKeys)
24
    {
25 1
        $this->writeExport($this->outputDir->getRealPath() . '/currencymap.php', $this->source->get());
26 1
        $this->writeSubMaps($currencyInfoKeys);
27 1
    }
28
29
    private function writeSubMaps(CurrencyInfoKeys $currencyInfoKeys)
30
    {
31 1
        array_map(function ($infoType) {
32 1
            $this->writeExport($this->getSubMapFileName($infoType), $this->getSubTypeMap($infoType));
33 1
        }, $currencyInfoKeys->get());
34 1
    }
35
36 1
    private function getSubMapFileName($infoType)
37
    {
38 1
        return $this->outputDir->getRealPath() . '/currencymap-' . $infoType . '.php';
39
    }
40
41 1
    private function getSubTypeMap($infoType)
42
    {
43 1
        return CurrencyInfoToSeparateMaps::build($this->source->get(), $infoType);
44
    }
45
46 1
    private function writeExport($fileName, $dataToWrite)
47
    {
48 1
        file_put_contents($fileName, "<?php\nreturn " . var_export($dataToWrite, true) . ";\n");
49 1
    }
50
}
51