<commit_before><?php
/**
 * Get one JSON file (arg #1), unset keys read from text file (arg. #2) and merge with other JSON file (arg. #3).
 * Backup first JSON and save result with the same name (as first JSON).
 */
/* include autoload to use composer's modules in this utility */
require_once(__DIR__ . '/../work/vendor/autoload.php');

if ($argc >= 3) {
    /* parse arguments: $src $additions */
    $fileComposer = $argv[1];
    $fileUnset = $argv[2];
    $fileOpts = $argv[3];
    /* load original 'composer.json' */
    $main = load_json($fileComposer);
    /* Load list to filter extra data and unset it */
    $unset = load_json($fileUnset);
    unset_node($main, $unset);
    /* load additional options */
    $opts = load_json($fileOpts);
    /* merge both JSONs and save as source with suffix '.merged' */
    $arrMerged = array_merge_recursive($main, $opts);
    $jsonMerged = json_encode($arrMerged, JSON_UNESCAPED_SLASHES);
    file_put_contents($fileComposer . '.merged.json', $jsonMerged);
    /* backup original source file and replace it by merged */
    $tstamp = date('.YmdHis');
    rename($fileComposer, $fileComposer . $tstamp);
    rename($fileComposer . '.merged.json', $fileComposer);
} else {
    $iAm = __FILE__;
    echo "\nUsage: $iAm 'source.json' 'unset.json' 'opts_to_add.json'";
}
return;

/**
 * Unset node in source array.
 *
 * @param array $sourceArr
 * @param mixed $node
 */
function unset_node(&$sourceArr, $node)
{
    if (is_array($node)) {
        foreach ($node as $key => $item) {
            if (isset($sourceArr[$key])) {
                unset_node($sourceArr[$key], $item);
            } elseif (isset($sourceArr[$item])) {
                unset_node($sourceArr, $item);
            } else {
                unset_node($sourceArr, $item);
            }
        }
    } else {
        if (isset($sourceArr[$node])) {
            unset($sourceArr[$node]);
        }
    }
}
<commit_msg>MOBI-606 - Create CLI commands for store configuration for Santegra<commit_after><?php
/**
 * Get one JSON file (arg #1), unset keys read from text file (arg. #2) and merge with other JSON file (arg. #3).
 * Backup first JSON and save result with the same name (as first JSON).
 */
/* include autoload to use composer's modules in this utility */
require_once(__DIR__ . '/../work/vendor/autoload.php');

if ($argc >= 3) {
    /* parse arguments: $src $additions */
    $fileComposer = $argv[1];
    $fileUnset = $argv[2];
    $fileOpts = $argv[3];
    /* load original 'composer.json' */
    $main = load_json($fileComposer);
    /* Load list to filter extra data and unset it */
    $unset = load_json($fileUnset);
    unset_node($main, $unset);
    /* load additional options */
    $opts = load_json($fileOpts);
    /* merge both JSONs and save as source with suffix '.merged' */
    $arrMerged = array_merge_recursive($main, $opts);
    $jsonMerged = json_encode($arrMerged, JSON_UNESCAPED_SLASHES);
    file_put_contents($fileComposer . '.merged.json', $jsonMerged);
    /* backup original source file and replace it by merged */
    $tstamp = date('.YmdHis');
    rename($fileComposer, $fileComposer . $tstamp);
    rename($fileComposer . '.merged.json', $fileComposer);
} else {
    $iAm = __FILE__;
    echo "\nUsage: $iAm 'source.json' 'unset.json' 'opts_to_add.json'";
}
return;

/**
 * Unset node in source array.
 *
 * @param array $sourceArr
 * @param mixed $node
 */
function unset_node(&$sourceArr, $node)
{
    if (is_array($node)) {
        foreach ($node as $key => $item) {
            if (isset($sourceArr[$key])) {
                unset_node($sourceArr[$key], $item);
            } elseif (!is_array($item) && isset($sourceArr[$item])) {
                unset_node($sourceArr, $item);
            } else {
                unset_node($sourceArr, $item);
            }
        }
    } else {
        if (isset($sourceArr[$node])) {
            unset($sourceArr[$node]);
        }
    }
}

{'fraction_non_alphanumeric': 0.15532994923857868, 'fraction_numerical': 0.004314720812182741, 'mean_word_length': 2.7676864244741872, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '4293590', 'n_tokens_mistral': 1281, 'n_tokens_neox': 1290, 'n_words': 339}