<commit_before><?php
/**
 * Created by PhpStorm.
 * User: air
 * Date: 02.09.17
 * Time: 7:22
 */

namespace ADiesel82\GeoService;


class ComposerScripts
{
    protected static $event;

    /**
     * Handle the post-install Composer event.
     *
     * @param  \Composer\Script\Event $event
     * @return void
     */
    public static function postInstall(Event $event)
    {
        self::$event = $event;
        self::downloadDatabases();
    }

    /**
     * Handle the post-update Composer event.
     *
     * @param  \Composer\Script\Event $event
     * @return void
     */
    public static function postUpdate(Event $event)
    {
        self::$event = $event;
        self::downloadDatabases();
    }

    protected static function downloadDatabases($event)
    {

        $io = self::$event->getIO();

        $app = new Application(getcwd());
        $config = $app->config('geo');
        $driver = $config['driver'];

        if (isset($config[$driver]['source'])) {
            try {
                $io->write("<info>" . $config[$driver] . " database update</info>");
                static::download($config[$driver]['source'], $config['store_path'], $config[$driver]['filename']);
                $io->write("<info>SxGeo database update finished</info>");
            } catch (\Exception $e) {
                $io->write("<warning>"$e->getMessage() . "</warning>");
            }
        }


    }

    protected static function download($downloadFrom, $destinationPath, $destinationFilename)
    {
        $io = self::$event->getIO();
        $io->write(sprintf("Database update url is `%s`...", $downloadFrom));
        $io->write("Starting download...");
        $tmpFilename = 'tmp_' . $destinationFilename;<commit_msg>fixes<commit_after><?php

namespace ADiesel82\GeoService;

use Composer\Script\Event;

class ComposerScripts
{
    protected static $event;

    /**
     * Handle the post-install Composer event.
     *
     * @param  \Composer\Script\Event $event
     * @return void
     */
    public static function postInstall(Event $event)
    {
        self::$event = $event;
        self::downloadDatabases();
    }

    /**
     * Handle the post-update Composer event.
     *
     * @param  \Composer\Script\Event $event
     * @return void
     */
    public static function postUpdate(Event $event)
    {
        self::$event = $event;
        self::downloadDatabases();
    }

    protected static function downloadDatabases($event)
    {

        $io = self::$event->getIO();

        $app = new Application(getcwd());
        $config = $app->config('geo');
        $driver = $config['driver'];

        if (isset($config[$driver]['source'])) {
            try {
                $io->write("<info>" . $config[$driver] . " database update</info>");
                static::download($config[$driver]['source'], $config['store_path'], $config[$driver]['filename']);
                $io->write("<info>SxGeo database update finished</info>");
            } catch (\Exception $e) {
                $io->write("<warning>" . $e->getMessage() . "</warning>");
            }
        }


    }

    protected static function download($downloadFrom, $destinationPath, $destinationFilename)
    {
        $io = self::$event->getIO();
        $io->write(sprintf("Database update url is `%s`...", $downloadFrom));
        $io->write("Starting download...");
        $tmpFilename = 'tmp_' . $destinationFilename;
{'fraction_non_alphanumeric': 0.16564952048823017, 'fraction_numerical': 0.003777971519907004, 'mean_word_length': 2.312800769971126, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6530958', 'n_tokens_mistral': 998, 'n_tokens_neox': 973, 'n_words': 201}