Installer::postInstall()   A
last analyzed

Complexity

Conditions 3
Paths 6

Size

Total Lines 25
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 17
CRAP Score 3.0303

Importance

Changes 3
Bugs 1 Features 0
Metric Value
eloc 21
dl 0
loc 25
ccs 17
cts 20
cp 0.85
rs 9.584
c 3
b 1
f 0
cc 3
nc 6
nop 0
crap 3.0303
1
<?php
2
3
namespace PierInfor\GeoLite;
4
5
use PierInfor\GeoLite\Updater;
6
use PierInfor\GeoLite\Downloader;
7
8
class Installer
9
{
10
11
    /**
12
     * postInstall
13
     *
14
     * provides access to the current Composer instance
15
     * run any post install tasks here
16
     */
17 1
    public static function postInstall()
18
    {
19 1
        echo "\n";
20 1
        $cityUpdateError = false;
21 1
        $updater = new Updater();
22
        $updater
23 1
            ->getFileManager()
24 1
            ->getDownloader()
25 1
            ->setAdapter(Downloader::ADAPTER_CURL)
26 1
            ->displayProgress(true);
27 1
        self::output('Update maxmind databases started');
28
        try {
29 1
            self::output('Updating city');
30 1
            $updater->setAdapter(Updater::ADAPTER_CITY)->update();
31
        } catch (\Exception $e) {
32
            $cityUpdateError = true;
33
            self::output('Download from maxmind failed : ' . $e->getMessage());
34
        }
35 1
        if (!$cityUpdateError) {
36 1
            self::output('Updating country');
37 1
            $updater->setAdapter(Updater::ADAPTER_COUNTRY)->update();
38 1
            self::output('Updating asn');
39 1
            $updater->setAdapter(Updater::ADAPTER_ASN)->update();
40
        }
41 1
        self::output('Update maxmind databases finished');
42
    }
43
44
    /**
45
     * console output
46
     *
47
     * @param string $msg
48
     * @param boolean $newline
49
     * @return void
50
     */
51 2
    public static function output(string $msg, $newline = true)
52
    {
53 2
        echo sprintf('%s - %s.%s', date('H:i:s'), $msg, ($newline) ? "\n" : '');
54
    }
55
}
56