<commit_before><?php

namespace Bolt\Storage\Collection;

use Bolt\Storage\Entity;
use Bolt\Storage\Mapping\MetadataDriver;
use Closure;
use Doctrine\Common\Collections\ArrayCollection;

/**
 * This class stores an array collection of Taxonomy Entities
 *
 * @author <NAME> <<EMAIL>>
 */
class Taxonomy extends ArrayCollection
{
    public $config;

    /**
     * Taxonomy constructor.
     *
     * @param array          $elements
     * @param MetadataDriver $metadata
     */
    public function __construct(array $elements = [], MetadataDriver $metadata = null)
    {
        parent::__construct($elements);
        if ($metadata) {
            $this->config = $metadata->getTaxonomyConfig();
        }
    }

    public function setFromPost($formValues, $entity)
    {
        if (isset($formValues['taxonomy'])) {
            $flatVals = $formValues['taxonomy'];
        } else {
            $flatVals = $formValues;
        }
        foreach ($flatVals as $field => $values) {
            if (!is_array($values)) {
                continue;
            }
            foreach ($values as $val) {
                $order = isset($formValues['taxonomy-order'][$field]) ? $formValues['taxonomy-order'][$field] : 0;
                if (isset($this->config[$field]['options'][$val])) {
                    $name = $this->config[$field]['options'][$val];
                } else {
                    $name = $val;
                }
                $taxentity = new Entity\Taxonomy([
                    'name'         => $name,
                    'content_id'   => $entity->getId(),
                    'contenttype'  => (string) $entity->getContenttype(),
                    'taxonomytype' => $field,
                    'slug'         => $val,
                    'sortorder'    => $order,
                ]);
                $this->add($taxentity);
            }
        }
    }

    public function setFromDatabaseValues($result)<commit_msg>handle normalise of array based values<commit_after><?php

namespace Bolt\Storage\Collection;

use Bolt\Storage\Entity;
use Bolt\Storage\Mapping\MetadataDriver;
use Closure;
use Doctrine\Common\Collections\ArrayCollection;

/**
 * This class stores an array collection of Taxonomy Entities
 *
 * @author <NAME> <<EMAIL>>
 */
class Taxonomy extends ArrayCollection
{
    public $config;

    /**
     * Taxonomy constructor.
     *
     * @param array          $elements
     * @param MetadataDriver $metadata
     */
    public function __construct(array $elements = [], MetadataDriver $metadata = null)
    {
        parent::__construct($elements);
        if ($metadata) {
            $this->config = $metadata->getTaxonomyConfig();
        }
    }

    public function setFromPost($formValues, $entity)
    {
        if (isset($formValues['taxonomy'])) {
            $flatVals = $formValues['taxonomy'];
        } else {
            $flatVals = $formValues;
        }
        foreach ($flatVals as $field => $values) {
            if (!is_array($values)) {
                continue;
            }
            foreach ($values as $val) {
                $order = isset($formValues['taxonomy-order'][$field]) ? $formValues['taxonomy-order'][$field] : 0;
                if (is_array($val) && isset($val['slug'])) {
                    $val = $val['slug'];
                }
                if (isset($this->config[$field]['options'][$val])) {
                    $name = $this->config[$field]['options'][$val];
                } else {
                    $name = $val;
                }
                $taxentity = new Entity\Taxonomy([
                    'name'         => $name,
                    'content_id'   => $entity->getId(),
                    'contenttype'  => (string) $entity->getContenttype(),
                    'taxonomytype' => $field,
                    'slug'         => $val,
                    'sortorder'    => $order,
                ]);
                $this->add($taxentity);
            }
        }
    }

    public function setFromDatabaseValues($result)
{'fraction_non_alphanumeric': 0.13963852438722457, 'fraction_numerical': 0.0004951720722951226, 'mean_word_length': 1.691538974017322, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 37, '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': '4422478', 'n_tokens_mistral': 1099, 'n_tokens_neox': 1065, 'n_words': 215}