<commit_before><?php

/**
 * Composer command tool
 *
 * @author <NAME> <<EMAIL>>
 * @link http://inji.ru/
 * @copyright 2015 <NAME>
 * @license https://github.com/injitools/cms-Inji/blob/master/LICENSE
 */
class ComposerCmd
{
    static function check()
    {
        if (!file_exists('composer/vendor/autoload.php')) {
            self::installComposer();
        }
        if (!file_exists(App::$primary->path . '/vendor/autoload.php')) {
            self::initComposer();
        }
    }

    static function installComposer()
    {
        if (!file_exists('composer/bin/composer')) {
            Tools::createDir('composer');
            if (!file_exists('composer/composer.phar')) {
                file_put_contents('composer/composerInstall.php', file_get_contents('https://getcomposer.org/installer'));
                $argv = ['install', '--install-dir', 'composer/'];
                header("Location: " . filter_input(INPUT_SERVER, 'REQUEST_URI'));
                include_once 'composer/composerInstall.php';
            }
            $composer = new Phar('composer/composer.phar');
            $composer->extractTo('composer/');
        }
    }

    static function initComposer()
    {

        $path = App::$primary->path . '/';
        if (!file_exists($path . 'composer.json')) {
            $json = [
                "name" => get_current_user() . "/" . App::$primary->name,
                "authors" => [
                    [
                        "name" => get_current_user(),
                        "email" => get_current_user() . "@" . INJI_DOMAIN_NAME
                    ]
                ],
                "require" => [
                    "php" => ">=5.5.0"
                ]
            ];
            Tools::createDir($path);
            file_put_contents($path . 'composer.json', json_encode($json, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
        }
        self::command('install', false, $path);
    }

    static function command($command, $needOutput = true, $path = null)
    {
        include_once 'composer/vendor/autoload.php';
        if ($needOutput) {
            $output = new Symfony\Component\Console\Output\StreamOutput(fopen('php://output', 'w'));
        } else {
            $output = null;
        }
        $path = str_replace('\\', '/', $path === null ? App::$primary->path . '/' : $path);
        $input = new Symfony\Component\Console\Input\StringInput($command . ' -d ' . $path);
        $app = new Composer\Console\Application();
        $app->setAutoExit(false);
        $app->run($input, $output);
    }

    static function requirePackage($packageName, $version = '')
    {
        $path = App::$primary->path . '/';
        if (file_exists($path . 'composer.lock')) {<commit_msg>fix directory<commit_after><?php

/**
 * Composer command tool
 *
 * @author <NAME> <<EMAIL>>
 * @link http://inji.ru/
 * @copyright 2015 <NAME>
 * @license https://github.com/injitools/cms-Inji/blob/master/LICENSE
 */
class ComposerCmd
{
    static function check()
    {
        if (!file_exists('composer/vendor/autoload.php')) {
            self::installComposer();
        }
        if (!file_exists(App::$primary->path . '/vendor/autoload.php')) {
            self::initComposer();
        }
    }

    static function installComposer()
    {
        if (!file_exists('composer/bin/composer')) {
            Tools::createDir('composer');
            if (!file_exists('composer/composer.phar')) {
                file_put_contents('composer/composerInstall.php', file_get_contents('https://getcomposer.org/installer'));
                $argv = ['install', '--install-dir', 'composer/'];
                header("Location: " . filter_input(INPUT_SERVER, 'REQUEST_URI'));
                include_once 'composer/composerInstall.php';
            }
            $composer = new Phar('composer/composer.phar');
            $composer->extractTo('composer/');
        }
    }

    static function initComposer()
    {

        $path = App::$primary->path . '/';
        if (!file_exists($path . 'composer.json')) {
            $json = [
                "name" => get_current_user() . "/" . App::$primary->name,
                "authors" => [
                    [
                        "name" => get_current_user(),
                        "email" => get_current_user() . "@" . INJI_DOMAIN_NAME
                    ]
                ],
                "require" => [
                    "php" => ">=5.5.0"
                ]
            ];
            Tools::createDir($path);
            file_put_contents($path . 'composer.json', json_encode($json, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
        }
        self::command('install', false, $path);
    }

    static function command($command, $needOutput = true, $path = null)
    {
        include_once 'composer/vendor/autoload.php';
        if ($needOutput) {
            $output = new Symfony\Component\Console\Output\StreamOutput(fopen('php://output', 'w'));
        } else {
            $output = null;
        }
        $path = str_replace('\\', '/', $path === null ? App::$primary->path . '/' : $path);
        $input = new Symfony\Component\Console\Input\StringInput($command . ' -d ' . $path);
        $app = new Composer\Console\Application();
        $app->setAutoExit(false);
        $dir = getcwd();
        $app->run($input, $output);
        chdir($dir);
    }

    static function requirePackage($packageName, $version = '')
    {
        $path = App::$primary->path . '/';
        if (file_exists($path . 'composer.lock')) {
{'fraction_non_alphanumeric': 0.16678687342228632, 'fraction_numerical': 0.0025243418680129825, 'mean_word_length': 1.9011506276150627, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 41, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4525142', 'n_tokens_mistral': 1670, 'n_tokens_neox': 1625, 'n_words': 250}