<commit_before><?php
/**
 * BEAR.Sunday install checker
 *
 * usage
 *
 * $ php path/to/check.php;
 *
 * @author <NAME> <<EMAIL>>
 */
$id = isset($_ENV['BEAR_DB_ID']) ? $_ENV['BEAR_DB_ID'] : 'root';
$password = isset($_ENV['BEAR_DB_PASSWORD']) ? $_ENV['BEAR_DB_PASSWORD'] : '';
$phpVersion = phpversion();
$apcVersion = phpversion("apc");

$vendorInstalled = file_exists(dirname(__DIR__) . '/vendor/composer/installed.json') ? 'OK' : 'NG';

echo "PHP: " . $phpVersion . PHP_EOL;
echo "APC: " . $apcVersion . PHP_EOL;
echo 'apc.enable_cli:' . ini_get('apc.enable_cli') . PHP_EOL;
echo 'DB ID/PASS:' . "{$id}/{$password}" . PHP_EOL;
echo 'variables_order: ' . ini_get('variables_order') . PHP_EOL;
if (phpversion("xhprof")) {
    echo 'xhprof.output_dir:' . ini_get('xhprof.output_dir') . PHP_EOL;
}

try {
    $pdo = new \PDO("mysql:host=localhost; dbname=blogbeartest", $id, $password);
    $dbConnection = 'OK';
} catch (Exception $e) {
    $dbConnection = $e->getMessage();
}
echo "DB connect:{$dbConnection}" . PHP_EOL;
echo "vendor installed: {$vendorInstalled}" . PHP_EOL;

echo "(option) xhprof: " . phpversion("xhprof") . PHP_EOL;
if (phpversion("xhprof")) {
    echo '(option) xhprof.output_dir:' . ini_get('xhprof.output_dir') . PHP_EOL;
}

$isInstallOk = (version_compare($phpVersion, '5.4', '>=')
            && (version_compare($apcVersion, '3.1.8', '>='))
            && ($vendorInstalled === 'OK')
            && ($dbConnection === 'OK'));
$insall = $isInstallOk ? 'OK' : 'NG';

echo PHP_EOL;
echo "BEAR.Sunday INSTALL: {$insall}" . PHP_EOL;
return $isInstallOk;<commit_msg>Refactor.<commit_after><?php
/**
 * BEAR.Sunday install checker
 *
 * usage
 *
 * $ php path/to/check.php;
 *
 * @author <NAME> <<EMAIL>>
 */

$ok = "\e[07;32m" . ' OK ' . "\033[0m";
$ng = "\e[07;31m" . ' NG ' . "\033[0m";

// PHP
$isPhpVersionOk = version_compare(phpversion(), '5.4', '>=') ? $ok : $ng;
echo "{$isPhpVersionOk}PHP:" . phpversion() . PHP_EOL;

// APC
$apcVersion = phpversion("apc");
$isAPCVersionOk = version_compare(phpversion("apc"), '3.1.8', '>=') ? $ok : $ng;
echo "{$isAPCVersionOk}APC:" . phpversion("apc") . PHP_EOL;
$apcEnableCli =  ini_get('apc.enable_cli') ? $ok : $ng;
echo "{$apcEnableCli}apc.enable_cli" . PHP_EOL;

//DB
$id = isset($_ENV['BEAR_DB_ID']) ? $_ENV['BEAR_DB_ID'] : 'root';
$password = isset($_ENV['BEAR_DB_PASSWORD']) ? $_ENV['BEAR_DB_PASSWORD'] : '';
try {
    $pdo = new \PDO("mysql:host=localhost; dbname=blogbeartest", $id, $password);
    $isDbConnectionOk = $ok;
} catch (Exception $e) {
    $isDbConnectionOk = $e->getMessage();
}
echo "{$isDbConnectionOk}DB connect({$id}/{$password})" . PHP_EOL;

// vendor
$isVendorInstalledOk = file_exists(dirname(__DIR__) . '/vendor/composer/installed.json') ? $ok : $ng;

echo "{$isVendorInstalledOk}Vendor install" . PHP_EOL;
// options
echo "(option) xhprof: " . phpversion("xhprof") . '(' . ini_get('xhprof.output_dir') . ')' . PHP_EOL;
if (phpversion("xhprof")) {
    echo '(option) xhprof.output_dir:' . ini_get('xhprof.output_dir') . PHP_EOL;
}

// info
echo '(info) variables_order: ' . ini_get('variables_order') . PHP_EOL;
echo '(info) php.ini: ' . ini_get('variables_order') . PHP_EOL;

$isEnvOk = ($isPhpVersionOk === $ok
            && ($isAPCVersionOk === $ok)
            && ($isVendorInstalledOk === $ok)
            && ($isDbConnectionOk === $ok));
$isInsallOk = $isEnvOk ? $ok : $ng;

echo PHP_EOL;
echo "BEAR.Sunday INSTALL: {$isInsallOk}" . PHP_EOL;
return $isEnvOk;
{'fraction_non_alphanumeric': 0.21484037963761865, 'fraction_numerical': 0.007477710670117918, 'mean_word_length': 4.2696969696969695, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 15, 'https://': 0, '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': '5417148', 'n_tokens_mistral': 1415, 'n_tokens_neox': 1387, 'n_words': 239}