<commit_before><?php

namespace Imanghafoori\Widgets\Utils;

/**
 * Class DebugInfo.
 */
class DebugInfo
{
    private $widget;
    private $html;
    private $policies;

    public function __construct()
    {
        $this->policies = app(Policies::class);
    }

    public function addIdentifierToHtml($widget, $html)
    {
        $this->widget = $widget;
        $this->html = $html;
        $this->addDebugInfo();
        $this->addHtmlComments();

        return $this->html;
    }

    private function addDebugInfo()
    {
        $tpl = $this->widget->template;
        if (str_contains($tpl, 'Widgets::')) {
            $tpl = str_replace('Widgets::', app()->getNamespace().'Widgets\\', $tpl);
        }

        $tpl = str_replace('.', '\\', $tpl);

        $this->html = "<span title='WidgetObj : ".get_class($this->widget).".php&#013;Template : {$tpl}.blade.php{$this->cacheState()}'>{$this->html}</span>";
    }

    /**
     * Generates a string of current cache configurations.
     * @return string
     */
    private function cacheState()
    {
        if (! $this->policies->widgetShouldUseCache()) {
            return ' &#013;Cache: is globally turned off (You should put "WIDGET_CACHE=true" in .env) ';
        }

        return " &#013;Cache : {$this->widget->cacheLifeTime} (min)' ";
    }

    private function addHtmlComments()
    {
        $this->html = "<!-- '{".get_class($this->widget)."' Widget Start -->".$this->html."<!-- '".get_class($this->widget)."' Widget End -->";
    }
}<commit_msg>- fix for debug info<commit_after><?php

namespace Imanghafoori\Widgets\Utils;

/**
 * Class DebugInfo.
 */
class DebugInfo
{
    private $widget;
    private $html;
    private $policies;

    public function __construct()
    {
        $this->policies = app(Policies::class);
    }

    public function addIdentifierToHtml($widget, $html)
    {
        $this->widget = $widget;
        $this->html = $html;
        $this->addDebugInfo();
        $this->addHtmlComments();

        return $this->html;
    }

    private function addDebugInfo()
    {
        $tpl = $this->widget->template;
        if (str_contains($tpl, 'Widgets::')) {
            $tpl = str_replace('Widgets::', app()->getNamespace().'Widgets\\', $tpl);
        }

        $tpl = str_replace('.', '\\', $tpl);

        $this->html = "<span title='WidgetObj : ".get_class($this->widget).".php&#013;Template : {$tpl}.blade.php{$this->cacheState()}'>{$this->html}</span>";
    }

    /**
     * Generates a string of current cache configurations.
     * @return string
     */
    private function cacheState()
    {
        if (! $this->policies->widgetShouldUseCache()) {
            return ' &#013;Cache: is globally turned off (You should put "enable_cache" => true in config\widgetize.php) ';
        }

        return " &#013;Cache : {$this->widget->cacheLifeTime} (min)' ";
    }

    private function addHtmlComments()
    {
        $this->html = "<!-- '{".get_class($this->widget)."' Widget Start -->".$this->html."<!-- '".get_class($this->widget)."' Widget End -->";
    }
}
{'fraction_non_alphanumeric': 0.1894087069525666, 'fraction_numerical': 0.005847953216374269, 'mean_word_length': 2.4948921679909195, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 54, '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': '4518348', 'n_tokens_mistral': 974, 'n_tokens_neox': 960, 'n_words': 187}