ScriptHandler::downloadData()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 16
rs 9.4285
cc 2
eloc 11
nc 2
nop 1
1
<?php
2
3
namespace ZfSnapGeoip\Composer;
4
5
use Composer\Script\Event;
6
7
/**
8
 * Composer script handler
9
 *
10
 * @author Witold Wasiczko <[email protected]>
11
 */
12
class ScriptHandler
13
{
14
    const ZEND_INDEX_PATH = 'zend-index-path';
15
16
    /**
17
     * Run download database file
18
     *
19
     * @param Event $event
20
     */
21
    public static function downloadData(Event $event)
22
    {
23
        $defaultOptions = [
24
            self::ZEND_INDEX_PATH => 'public/index.php',
25
            ];
26
        $newOptions = $event->getComposer()->getPackage()->getExtra();
27
        $options = array_merge($defaultOptions, $newOptions);
28
        $zendIndexPath = $options[self::ZEND_INDEX_PATH];
29
        $geoipDownloadCmd = 'geoip download';
30
31
        if ($event->getName() === 'post-install-cmd') {
32
            $geoipDownloadCmd .= ' --no-clobber';
33
        }
34
        $cmd = sprintf('php %s %s', $zendIndexPath, $geoipDownloadCmd);
35
        system($cmd);
36
    }
37
38
}
39