Installer::output()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 1
nop 2
crap 2
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