<commit_before><?php

namespace Deimos\Flow\Extension\TSimple;

use Deimos\Flow\FlowFunction;

class TVariable extends FlowFunction
{

    /**
     * @var array
     */
    protected $attributes = [];

    /**
     * @var string
     */
    protected $callback;

    protected function variable($variable)
    {
        return trim($variable, '"\' ');
    }

    protected function init()
    {
        $variable = array_shift($this->data);
        $variable = $this->variable($variable);

        $this->attributes[] = &$variable;

        $callback = '';

        $isVariable = true;
        $isCallback = true;

        foreach ($this->data as $dataValue)
        {
            if ($isVariable)
            {
                if ($dataValue === '|')
                {
                    $isVariable = false;
                    continue;
                }

                $variable .= $dataValue;
            }
            else
            {
                if ($isCallback)
                {
                    if ($dataValue === ':')
                    {
                        $isCallback = false;
                        continue;
                    }

                    $callback .= $dataValue;
                }
                else if ($dataValue !== ':')
                {
                    $this->attributes[] = $this->variable($dataValue);
                }
            }
        }

        return $callback;
    }

    public function view()
    {
        $callback = $this->init();

        if (!$callback)
        {
            $callback = 'escape';
        }

//        $variable = current($this->attributes);

        $storage = '$this->configure->di()->call(\'' . $callback . '\', ';
        $export  = var_export($this->attributes, true);
        $export  = preg_replace('~\'(\$[\w->:]+)\'~', '$1', $export);
        $storage .= str_replace(["\n", "\r"], '', $export) . ')';
<commit_msg>add default<commit_after><?php

namespace Deimos\Flow\Extension\TSimple;

use Deimos\Flow\FlowFunction;

class TVariable extends FlowFunction
{

    /**
     * @var array
     */
    protected $attributes = [];

    /**
     * @var string
     */
    protected $callback;

    protected function variable($variable)
    {
        return trim($variable, '"\' ');
    }

    protected function init()
    {
        $variable = array_shift($this->data);
        $variable = $this->variable($variable);

        $this->attributes[] = &$variable;

        $callback = '';

        $isVariable = true;
        $isCallback = true;

        foreach ($this->data as $dataValue)
        {
            if ($isVariable)
            {
                if ($dataValue === '|')
                {
                    $isVariable = false;
                    continue;
                }

                $variable .= $dataValue;
            }
            else
            {
                if ($isCallback)
                {
                    if ($dataValue === ':')
                    {
                        $isCallback = false;
                        continue;
                    }

                    $callback .= $dataValue;
                }
                else if ($dataValue !== ':')
                {
                    $this->attributes[] = $this->variable($dataValue);
                }
            }
        }

        return $callback;
    }

    public function view()
    {
        $callback = $this->init();

        $isDefault = $callback === 'default';

        if (!$callback || $isDefault)
        {
            $callback = 'escape';
        }

        $variable = current($this->attributes);

        if ($isDefault && $variable{0} === '$')
        {
            array_shift($this->attributes);
            $default = array_shift($this->attributes);

            if ($default{0} !== '$')
            {
                $default = '\'' . $default . '\'';
            }

            $storage = sprintf(
                '( empty(%s) ? $this->configure->di()->escape(%s): $this->configure->di()->escape(%s) )',
                $variable,
                $default,
                $variable
            );
        }
        else
        {
            $storage = '$this->configure->di()->call(\'' . $callback . '\', ';
            $export  = var_export($this->attributes, true);
            $export  = preg_replace('~\'(\$[\w->:]+)\'~', '$1', $export);
            $storage .= str_replace(["\n", "\r"], '', $export) . ')';
        }

{'fraction_non_alphanumeric': 0.15824915824915825, 'fraction_numerical': 0.0008978675645342312, 'mean_word_length': 1.1768441621885686, 'pattern_counts': {'":': 0, '<': 5, '<?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': '7137235', 'n_tokens_mistral': 1206, 'n_tokens_neox': 1125, 'n_words': 206}