Completed
Push — master ( 7d1c48...f25f2d )
by Hannes
01:28
created

build_currencies.php ➔ render_template()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 2
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
1
<?php
2
/**
3
 * Script to generate ISO 4217 currencies
4
 *
5
 * Usage: php build_currencies.php
6
 */
7
8
include 'vendor/autoload.php';
9
10
$srcPath = realpath(__DIR__ . '/../src/Currency');
11
$testPath = realpath(__DIR__ . '/../tests/Currency');
12
13
foreach ((new Alcohol\ISO4217)->getAll() as $def) {
14
    echo "Generating {$def['alpha3']}";
15
16
    $def['classname'] = $def['alpha3'] == 'TRY' ? '_TRY' : $def['alpha3'];
17
18
    file_put_contents(
19
        "$srcPath/{$def['classname']}.php",
20
        '<?php' . render_template('currency_tmpl.php', $def)
21
    );
22
23
    file_put_contents(
24
        "$testPath/{$def['classname']}Test.php",
25
        '<?php' . render_template('test_tmpl.php', $def)
26
    );
27
28
    echo " [DONE]\n";
29
}
30
31
function render_template($template, array $values)
32
{
33
    extract($values);
34
    ob_start();
35
    include __DIR__ . DIRECTORY_SEPARATOR . $template;
36
    $content = ob_get_contents();
37
    ob_end_clean();
38
    return $content;
39
}
40