<commit_before><?php

namespace jumper423\behaviors;

use yii\behaviors\AttributeBehavior;
use yii\helpers\Json;

class JsonBehavior extends AttributeBehavior
{
    /**
     * @inheritdoc
     */
    public function evaluateAttributes($event)
    {
        if (!empty($this->attributes[$event->name])) {
            $attributes = (array) $this->attributes[$event->name];
            foreach ($attributes as $attribute) {
                if (is_string($attribute)) {
                    if (!is_string($this->owner->$attribute) && !is_null($this->owner->$attribute)) {
                        $this->owner->$attribute = Json::encode($this->owner->$attribute);
                    }
                }
            }
        }
    }<commit_msg>decode/encode<commit_after><?php

namespace jumper423\behaviors;

use yii\behaviors\AttributeBehavior;
use yii\helpers\Json;

class JsonBehavior extends AttributeBehavior
{
    const DECODE = 'decode';
    const ENCODE = 'encode';

    public $type = self::ENCODE;

    /**
     * @inheritdoc
     */
    public function evaluateAttributes($event)
    {
        if (!empty($this->attributes[$event->name])) {
            $attributes = (array)$this->attributes[$event->name];
            switch ($this->type) {
                case self::ENCODE:
                    foreach ($attributes as $attribute) {
                        if (is_string($attribute)) {
                            if (!is_string($this->owner->$attribute) && !is_null($this->owner->$attribute)) {
                                $this->owner->$attribute = Json::encode($this->owner->$attribute);
                            }
                        }
                    }
                    break;
                case self::DECODE:
                    foreach ($attributes as $attribute) {
                        if (is_array($attribute)) {
                            if (!is_array($this->owner->$attribute) && !is_null($this->owner->$attribute)) {
                                $this->owner->$attribute = Json::decode($this->owner->$attribute);
                            }
                        }
                    }
                    break;
            }
        }
    }
{'fraction_non_alphanumeric': 0.13746017296313154, 'fraction_numerical': 0.0027309968138370506, 'mean_word_length': 1.5005688282138794, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 36, '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': '3550051', 'n_tokens_mistral': 566, 'n_tokens_neox': 544, 'n_words': 89}