<commit_before><?php
namespace Qobo\Utils\ModuleConfig\Parser\Ini;

use StdClass;

/**
 * Config INI Parser
 *
 * This parser is useful for module config INI processing.
 *
 * @author <NAME> <<EMAIL>>
 */
class ConfigParser extends AbstractIniParser
{
    /**
     * JSON schema
     *
     * This can either be a string, pointing to the file
     * or an StdClass with an instance of an already parsed
     * schema
     *
     * @var string|StdClass $schema JSON schema
     */
    protected $schema = 'file://' . __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'Schema' . DIRECTORY_SEPARATOR . 'config.json';

    /**
     * Merge with default values
     *
     * @param object $data Data to merge with defaults
     * @return object
     */
    protected function mergeWithDefaults($data = null)
    {
        // [table] section
        if (!property_exists($data, 'table')) {
            $data->table = new StdClass();
        }

        // [table]icon
        if (!property_exists($data->table, 'icon') || empty($data->table->icon)) {
            $data->table->icon = 'cube';
        }

        // [table]searchable
        if (!property_exists($data->table, 'searchable')) {
            $data->table->searchable = true;
        }

        // [table]lookup_fields
        if (!property_exists($data->table, 'lookup_fields')) {
            $data->table->lookup_fields = [];
        }

        if (is_string($data->table->lookup_fields)) {
            $data->table->lookup_fields = explode(',', $data->table->lookup_fields);
        }

        // [table]typeahead_fields
        if (!property_exists($data->table, 'typeahead_fields')) {
            $data->table->typeahead_fields = [];
        }

        if (is_string($data->table->typeahead_fields)) {
            $data->table->typeahead_fields = explode(',', $data->table->typeahead_fields);
        }

        // [table]display_field
        if (!property_exists($data->table, 'display_field')) {
            $this->warnings = array_merge($this->warnings, ["'display_field' is not set in 'table' section"]);
        }

        // [virtualFields] section
        if (!property_exists($data, 'virtualFields')) {
            $data->virtualFields = new StdClass();
        }
        $virtualFields = json_decode(json_encode($data->virtualFields), true);
        foreach ($virtualFields as $virtualField => $realFields) {
            if (is_string($realFields)) {
                $data->virtualFields->$virtualField = explode(',', $realFields);
            }
        }

        // [associations] section
        if (!property_exists($data, 'associations')) {
            $data->associations = new StdClass();
        }

        // [associations]hide_associations
        if (!property_exists($data->associations, 'hide_associations')) {
            $data->associations->hide_associations = [];
        }

        if (is_string($data->associations->hide_associations)) {
            $data->associations->hide_associations = explode(',', $data->associations->hide_associations);
        }

        return $data;
    }
}<commit_msg>Set default for associationLabels (task #3862)<commit_after><?php
namespace Qobo\Utils\ModuleConfig\Parser\Ini;

use StdClass;

/**
 * Config INI Parser
 *
 * This parser is useful for module config INI processing.
 *
 * @author <NAME> <<EMAIL>>
 */
class ConfigParser extends AbstractIniParser
{
    /**
     * JSON schema
     *
     * This can either be a string, pointing to the file
     * or an StdClass with an instance of an already parsed
     * schema
     *
     * @var string|StdClass $schema JSON schema
     */
    protected $schema = 'file://' . __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'Schema' . DIRECTORY_SEPARATOR . 'config.json';

    /**
     * Merge with default values
     *
     * @param object $data Data to merge with defaults
     * @return object
     */
    protected function mergeWithDefaults($data = null)
    {
        // [table] section
        if (!property_exists($data, 'table')) {
            $data->table = new StdClass();
        }

        // [table]icon
        if (!property_exists($data->table, 'icon') || empty($data->table->icon)) {
            $data->table->icon = 'cube';
        }

        // [table]searchable
        if (!property_exists($data->table, 'searchable')) {
            $data->table->searchable = true;
        }

        // [table]lookup_fields
        if (!property_exists($data->table, 'lookup_fields')) {
            $data->table->lookup_fields = [];
        }

        if (is_string($data->table->lookup_fields)) {
            $data->table->lookup_fields = explode(',', $data->table->lookup_fields);
        }

        // [table]typeahead_fields
        if (!property_exists($data->table, 'typeahead_fields')) {
            $data->table->typeahead_fields = [];
        }

        if (is_string($data->table->typeahead_fields)) {
            $data->table->typeahead_fields = explode(',', $data->table->typeahead_fields);
        }

        // [table]display_field
        if (!property_exists($data->table, 'display_field')) {
            $this->warnings = array_merge($this->warnings, ["'display_field' is not set in 'table' section"]);
        }

        // [virtualFields] section
        if (!property_exists($data, 'virtualFields')) {
            $data->virtualFields = new StdClass();
        }
        $virtualFields = json_decode(json_encode($data->virtualFields), true);
        foreach ($virtualFields as $virtualField => $realFields) {
            if (is_string($realFields)) {
                $data->virtualFields->$virtualField = explode(',', $realFields);
            }
        }

        // [associations] section
        if (!property_exists($data, 'associations')) {
            $data->associations = new StdClass();
        }

        // [associations]hide_associations
        if (!property_exists($data->associations, 'hide_associations')) {
            $data->associations->hide_associations = [];
        }

        if (is_string($data->associations->hide_associations)) {
            $data->associations->hide_associations = explode(',', $data->associations->hide_associations);
        }

        // [associationLabels] section
        if (!property_exists($data, 'associationLabels')) {
            $data->associationLabels = new StdClass();
        }

        return $data;
    }
}
{'fraction_non_alphanumeric': 0.14757433489827856, 'fraction_numerical': 0.0006259780907668231, 'mean_word_length': 2.297729618163055, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 100, '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': '4545410', 'n_tokens_mistral': 1850, 'n_tokens_neox': 1796, 'n_words': 361}